@@ -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.
@@ -429,10 +407,9 @@ interface INodeBasicSettings extends ISharedSettings {
429407}
430408/**
431409 * Common API for entities that expose status handlers.
432- * @interface IStatusInterface
433- * @extends EventEmitter
410+ * @typedef IStatusInterface
434411 */
435- interface IStatusInterface extends EventEmitter {
412+ type IStatusInterface < TEventEmitter extends SplitIO . IEventEmitter = SplitIO . EventEmitter > = TEventEmitter & {
436413 /**
437414 * Constant object containing the SDK events for you to use.
438415 * @property {EventConsts } Event
@@ -460,10 +437,9 @@ interface IStatusInterface extends EventEmitter {
460437}
461438/**
462439 * Common definitions between clients for different environments interface.
463- * @interface IBasicClient
464- * @extends IStatusInterface
440+ * @typedef IBasicClient
465441 */
466- interface IBasicClient extends IStatusInterface {
442+ type IBasicClient < TEventEmitter extends SplitIO . IEventEmitter = SplitIO . EventEmitter > = IStatusInterface < TEventEmitter > & {
467443 /**
468444 * Destroys the client instance.
469445 * In 'standalone' mode, this method will flush any pending impressions and events, and stop the synchronization of feature flag definitions with the backend.
@@ -502,6 +478,42 @@ interface IBasicSDK {
502478 * For the SDK package information see {@link https://www.npmjs.com/package/@splitsoftware/splitio}
503479 */
504480declare namespace SplitIO {
481+ /**
482+ * EventEmitter interface based on a subset of the NodeJS.EventEmitter methods. Used by the JavaScript Browser SDK and React Native SDK.
483+ */
484+ interface IEventEmitter {
485+ addListener ( event : string , listener : ( ...args : any [ ] ) => void ) : this
486+ on ( event : string , listener : ( ...args : any [ ] ) => void ) : this
487+ once ( event : string , listener : ( ...args : any [ ] ) => void ) : this
488+ removeListener ( event : string , listener : ( ...args : any [ ] ) => void ) : this
489+ off ( event : string , listener : ( ...args : any [ ] ) => void ) : this
490+ removeAllListeners ( event ?: string ) : this
491+ emit ( event : string , ...args : any [ ] ) : boolean
492+ }
493+
494+ /**
495+ * NodeJS.EventEmitter interface. Used by the JavaScript SDK for both flavours: server-side (NodeJS) and client-side (Browser).
496+ *
497+ * @see {@link https://nodejs.org/api/events.html }
498+ */
499+ interface EventEmitter extends IEventEmitter {
500+ addListener ( event : string | symbol , listener : ( ...args : any [ ] ) => void ) : this;
501+ on ( event : string | symbol , listener : ( ...args : any [ ] ) => void ) : this;
502+ once ( event : string | symbol , listener : ( ...args : any [ ] ) => void ) : this;
503+ removeListener ( event : string | symbol , listener : ( ...args : any [ ] ) => void ) : this;
504+ off ( event : string | symbol , listener : ( ...args : any [ ] ) => void ) : this;
505+ removeAllListeners ( event ?: string | symbol ) : this;
506+ emit ( event : string | symbol , ...args : any [ ] ) : boolean ;
507+ setMaxListeners ( n : number ) : this;
508+ getMaxListeners ( ) : number ;
509+ listeners ( event : string | symbol ) : Function [ ] ;
510+ rawListeners ( event : string | symbol ) : Function [ ] ;
511+ listenerCount ( type : string | symbol ) : number ;
512+ // Added in Node 6...
513+ prependListener ( event : string | symbol , listener : ( ...args : any [ ] ) => void ) : this;
514+ prependOnceListener ( event : string | symbol , listener : ( ...args : any [ ] ) => void ) : this;
515+ eventNames ( ) : Array < string | symbol > ;
516+ }
505517 /**
506518 * Feature flag treatment value, returned by getTreatment.
507519 * @typedef {string } Treatment
@@ -1224,30 +1236,30 @@ declare namespace SplitIO {
12241236 manager ( ) : IManager
12251237 }
12261238 /**
1227- * This represents the interface for the SDK instance with synchronous storage.
1239+ * This represents the interface for the SDK instance with synchronous storage and client-side API .
12281240 * @interface IBrowserSDK
12291241 * @extends IBasicSDK
12301242 */
1231- interface IBrowserSDK extends IBasicSDK {
1243+ interface IBrowserSDK < TEventEmitter extends IEventEmitter = EventEmitter > extends IBasicSDK {
12321244 /**
12331245 * Returns the default client instance of the SDK.
12341246 * @function client
12351247 * @returns {IBrowserClient } The client instance.
12361248 */
1237- client ( ) : IBrowserClient ,
1249+ client ( ) : IBrowserClient < TEventEmitter > ,
12381250 /**
12391251 * Returns a shared client of the SDK.
12401252 * @function client
12411253 * @param {SplitKey } key The key for the new client instance.
12421254 * @returns {IBrowserClient } The client instance.
12431255 */
1244- client ( key : SplitKey ) : IBrowserClient
1256+ client ( key : SplitKey ) : IBrowserClient < TEventEmitter >
12451257 /**
12461258 * Returns a manager instance of the SDK to explore available information.
12471259 * @function manager
12481260 * @returns {IManager } The manager instance.
12491261 */
1250- manager ( ) : IManager ,
1262+ manager ( ) : IManager < TEventEmitter > ,
12511263 /**
12521264 * User consent API.
12531265 * @property UserConsent
@@ -1379,10 +1391,9 @@ declare namespace SplitIO {
13791391 * 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.
13801392 * 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'`).
13811393 *
1382- * @interface IBrowserClient
1383- * @extends IBasicClient
1394+ * @typedef IBrowserClient
13841395 */
1385- interface IBrowserClient extends IBasicClient {
1396+ type IBrowserClient < TEventEmitter extends IEventEmitter = EventEmitter > = IBasicClient < TEventEmitter > & {
13861397 /**
13871398 * Returns a Treatment value, which is the treatment string for the given feature.
13881399 *
@@ -1613,10 +1624,9 @@ declare namespace SplitIO {
16131624 }
16141625 /**
16151626 * Representation of a manager instance with synchronous storage of the SDK.
1616- * @interface IManager
1617- * @extends IStatusInterface
1627+ * @typedef IManager
16181628 */
1619- interface IManager extends IStatusInterface {
1629+ type IManager < TEventEmitter extends IEventEmitter = EventEmitter > = IStatusInterface < TEventEmitter > & {
16201630 /**
16211631 * Get the array of feature flag names.
16221632 * @function names
0 commit comments