@@ -8,28 +8,6 @@ import { RequestOptions } from "http";
88export as namespace SplitIO ;
99export = SplitIO ;
1010
11- /**
12- * NodeJS.EventEmitter interface
13- * @see {@link https://nodejs.org/api/events.html }
14- */
15- interface EventEmitter {
16- addListener ( event : string | symbol , listener : ( ...args : any [ ] ) => void ) : this;
17- on ( event : string | symbol , listener : ( ...args : any [ ] ) => void ) : this;
18- once ( event : string | symbol , listener : ( ...args : any [ ] ) => void ) : this;
19- removeListener ( event : string | symbol , listener : ( ...args : any [ ] ) => void ) : this;
20- off ( event : string | symbol , listener : ( ...args : any [ ] ) => void ) : this;
21- removeAllListeners ( event ?: string | symbol ) : this;
22- setMaxListeners ( n : number ) : this;
23- getMaxListeners ( ) : number ;
24- listeners ( event : string | symbol ) : Function [ ] ;
25- rawListeners ( event : string | symbol ) : Function [ ] ;
26- emit ( event : string | symbol , ...args : any [ ] ) : boolean ;
27- listenerCount ( type : string | symbol ) : number ;
28- // Added in Node 6...
29- prependListener ( event : string | symbol , listener : ( ...args : any [ ] ) => void ) : this;
30- prependOnceListener ( event : string | symbol , listener : ( ...args : any [ ] ) => void ) : this;
31- eventNames ( ) : Array < string | symbol > ;
32- }
3311/**
3412 * @typedef {Object } EventConsts
3513 * @property {string } SDK_READY The ready event.
@@ -430,10 +408,9 @@ interface INodeBasicSettings extends ISharedSettings {
430408}
431409/**
432410 * Common API for entities that expose status handlers.
433- * @interface IStatusInterface
434- * @extends EventEmitter
411+ * @typedef IStatusInterface
435412 */
436- interface IStatusInterface extends EventEmitter {
413+ type IStatusInterface < TEventEmitter extends SplitIO . IEventEmitter = SplitIO . EventEmitter > = TEventEmitter & {
437414 /**
438415 * Constant object containing the SDK events for you to use.
439416 * @property {EventConsts } Event
@@ -461,10 +438,9 @@ interface IStatusInterface extends EventEmitter {
461438}
462439/**
463440 * Common definitions between clients for different environments interface.
464- * @interface IBasicClient
465- * @extends IStatusInterface
441+ * @typedef IBasicClient
466442 */
467- interface IBasicClient extends IStatusInterface {
443+ type IBasicClient < TEventEmitter extends SplitIO . IEventEmitter = SplitIO . EventEmitter > = IStatusInterface < TEventEmitter > & {
468444 /**
469445 * Destroys the client instance.
470446 * In 'standalone' mode, this method will flush any pending impressions and events, and stop the synchronization of feature flag definitions with the backend.
@@ -503,6 +479,42 @@ interface IBasicSDK {
503479 * For the SDK package information see {@link https://www.npmjs.com/package/@splitsoftware/splitio}
504480 */
505481declare namespace SplitIO {
482+ /**
483+ * EventEmitter interface based on a subset of the NodeJS.EventEmitter methods. Used by the JavaScript Browser SDK and React Native SDK.
484+ */
485+ interface IEventEmitter {
486+ addListener ( event : string , listener : ( ...args : any [ ] ) => void ) : this
487+ on ( event : string , listener : ( ...args : any [ ] ) => void ) : this
488+ once ( event : string , listener : ( ...args : any [ ] ) => void ) : this
489+ removeListener ( event : string , listener : ( ...args : any [ ] ) => void ) : this
490+ off ( event : string , listener : ( ...args : any [ ] ) => void ) : this
491+ removeAllListeners ( event ?: string ) : this
492+ emit ( event : string , ...args : any [ ] ) : boolean
493+ }
494+
495+ /**
496+ * NodeJS.EventEmitter interface. Used by the JavaScript SDK for both flavours: server-side (NodeJS) and client-side (Browser).
497+ *
498+ * @see {@link https://nodejs.org/api/events.html }
499+ */
500+ interface EventEmitter extends IEventEmitter {
501+ addListener ( event : string | symbol , listener : ( ...args : any [ ] ) => void ) : this;
502+ on ( event : string | symbol , listener : ( ...args : any [ ] ) => void ) : this;
503+ once ( event : string | symbol , listener : ( ...args : any [ ] ) => void ) : this;
504+ removeListener ( event : string | symbol , listener : ( ...args : any [ ] ) => void ) : this;
505+ off ( event : string | symbol , listener : ( ...args : any [ ] ) => void ) : this;
506+ removeAllListeners ( event ?: string | symbol ) : this;
507+ emit ( event : string | symbol , ...args : any [ ] ) : boolean ;
508+ setMaxListeners ( n : number ) : this;
509+ getMaxListeners ( ) : number ;
510+ listeners ( event : string | symbol ) : Function [ ] ;
511+ rawListeners ( event : string | symbol ) : Function [ ] ;
512+ listenerCount ( type : string | symbol ) : number ;
513+ // Added in Node 6...
514+ prependListener ( event : string | symbol , listener : ( ...args : any [ ] ) => void ) : this;
515+ prependOnceListener ( event : string | symbol , listener : ( ...args : any [ ] ) => void ) : this;
516+ eventNames ( ) : Array < string | symbol > ;
517+ }
506518 /**
507519 * Feature flag treatment value, returned by getTreatment.
508520 * @typedef {string } Treatment
@@ -1237,30 +1249,30 @@ declare namespace SplitIO {
12371249 getState ( keys ?: SplitKey [ ] ) : PreloadedData ,
12381250 }
12391251 /**
1240- * This represents the interface for the SDK instance with synchronous storage.
1252+ * This represents the interface for the SDK instance with synchronous storage and client-side API .
12411253 * @interface IBrowserSDK
12421254 * @extends IBasicSDK
12431255 */
1244- interface IBrowserSDK extends IBasicSDK {
1256+ interface IBrowserSDK < TEventEmitter extends IEventEmitter = EventEmitter > extends IBasicSDK {
12451257 /**
12461258 * Returns the default client instance of the SDK.
12471259 * @function client
12481260 * @returns {IBrowserClient } The client instance.
12491261 */
1250- client ( ) : IBrowserClient ,
1262+ client ( ) : IBrowserClient < TEventEmitter > ,
12511263 /**
12521264 * Returns a shared client of the SDK.
12531265 * @function client
12541266 * @param {SplitKey } key The key for the new client instance.
12551267 * @returns {IBrowserClient } The client instance.
12561268 */
1257- client ( key : SplitKey ) : IBrowserClient
1269+ client ( key : SplitKey ) : IBrowserClient < TEventEmitter >
12581270 /**
12591271 * Returns a manager instance of the SDK to explore available information.
12601272 * @function manager
12611273 * @returns {IManager } The manager instance.
12621274 */
1263- manager ( ) : IManager ,
1275+ manager ( ) : IManager < TEventEmitter > ,
12641276 /**
12651277 * User consent API.
12661278 * @property UserConsent
@@ -1392,10 +1404,9 @@ declare namespace SplitIO {
13921404 * This represents the interface for the Client instance on client-side, where the user key is bound to the instance on creation and does not need to be provided on each method call.
13931405 * This interface is the default when importing the SDK in the Browser, or when importing the 'client' sub-package (e.g., `import { SplitFactory } from '@splitsoftware/splitio/client'`).
13941406 *
1395- * @interface IBrowserClient
1396- * @extends IBasicClient
1407+ * @typedef IBrowserClient
13971408 */
1398- interface IBrowserClient extends IBasicClient {
1409+ type IBrowserClient < TEventEmitter extends IEventEmitter = EventEmitter > = IBasicClient < TEventEmitter > & {
13991410 /**
14001411 * Returns a Treatment value, which is the treatment string for the given feature.
14011412 *
@@ -1626,10 +1637,9 @@ declare namespace SplitIO {
16261637 }
16271638 /**
16281639 * Representation of a manager instance with synchronous storage of the SDK.
1629- * @interface IManager
1630- * @extends IStatusInterface
1640+ * @typedef IManager
16311641 */
1632- interface IManager extends IStatusInterface {
1642+ type IManager < TEventEmitter extends IEventEmitter = EventEmitter > = IStatusInterface < TEventEmitter > & {
16331643 /**
16341644 * Get the array of feature flag names.
16351645 * @function names
0 commit comments