@inweb/eventemitter2 25.3.18 → 25.3.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/eventemitter2.js.map +1 -1
- package/dist/eventemitter2.module.js.map +1 -1
- package/lib/index.d.ts +4 -4
- package/package.json +1 -1
- package/src/index.ts +4 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"eventemitter2.js","sources":["../src/index.ts"],"sourcesContent":["///////////////////////////////////////////////////////////////////////////////\n// Copyright (C) 2002-2021, Open Design Alliance (the \"Alliance\").\n// All rights reserved.\n//\n// This software and its documentation and related materials are owned by\n// the Alliance. The software may only be incorporated into application\n// programs owned by members of the Alliance, subject to a signed\n// Membership Agreement and Supplemental Software License Agreement with the\n// Alliance. The structure and organization of this software are the valuable\n// trade secrets of the Alliance and its suppliers. The software is also\n// protected by copyright law and international treaty provisions. Application\n// programs incorporating this software must include the following statement\n// with their copyright notices:\n//\n// This application incorporates Open Design Alliance software pursuant to a\n// license agreement with Open Design Alliance.\n// Open Design Alliance Copyright (C) 2002-2021 by Open Design Alliance.\n// All rights reserved.\n//\n// By use of this software, its documentation or related materials, you\n// acknowledge and accept the above terms.\n///////////////////////////////////////////////////////////////////////////////\n\nexport interface IEvent {\n type: string;\n}\n\nexport interface IEventEmitter {\n addEventListener(type: string, listener: (event: IEvent) => void): this;\n removeEventListener(type: string, listener: (event: IEvent) => void): this;\n removeAllListeners(type?: string): this;\n emitEvent(event: IEvent): boolean;\n on(type: string, listener: (event:
|
|
1
|
+
{"version":3,"file":"eventemitter2.js","sources":["../src/index.ts"],"sourcesContent":["///////////////////////////////////////////////////////////////////////////////\n// Copyright (C) 2002-2021, Open Design Alliance (the \"Alliance\").\n// All rights reserved.\n//\n// This software and its documentation and related materials are owned by\n// the Alliance. The software may only be incorporated into application\n// programs owned by members of the Alliance, subject to a signed\n// Membership Agreement and Supplemental Software License Agreement with the\n// Alliance. The structure and organization of this software are the valuable\n// trade secrets of the Alliance and its suppliers. The software is also\n// protected by copyright law and international treaty provisions. Application\n// programs incorporating this software must include the following statement\n// with their copyright notices:\n//\n// This application incorporates Open Design Alliance software pursuant to a\n// license agreement with Open Design Alliance.\n// Open Design Alliance Copyright (C) 2002-2021 by Open Design Alliance.\n// All rights reserved.\n//\n// By use of this software, its documentation or related materials, you\n// acknowledge and accept the above terms.\n///////////////////////////////////////////////////////////////////////////////\n\nexport interface IEvent {\n type: string;\n}\n\nexport interface IEventEmitter {\n addEventListener(type: string, listener: (event: IEvent) => void): this;\n removeEventListener(type: string, listener: (event: IEvent) => void): this;\n removeAllListeners(type?: string): this;\n emitEvent(event: IEvent): boolean;\n on(type: string, listener: (event: any) => void): this;\n off(type: string, listener: (event: any) => void): this;\n emit(event: string | object, ...args: any[]): boolean;\n}\n\n/**\n * The minimal basic Event that can be emitted by a {@link EventEmitter2}.\n */\nexport interface Event<T extends string = string> extends IEvent {\n type: T;\n}\n\n/**\n * Event emitter for custom objects.\n */\nexport class EventEmitter2<EventMap extends Record<string, any> = Record<string, any>> implements IEventEmitter {\n private _listeners = undefined;\n\n /**\n * Registers a new listener for an event type.\n *\n * @param type - The type of event to listen to.\n * @param listener - The function that gets called when the event is fired.\n */\n addEventListener<T extends keyof EventMap>(type: T, listener: (event: EventMap[T]) => void): this {\n if (this._listeners === undefined) this._listeners = {};\n if (this._listeners[type] === undefined) this._listeners[type] = [];\n this._listeners[type].push(listener);\n return this;\n }\n\n /**\n * Removes the listener from an event type.\n *\n * @param type - The type of the listener that gets removed.\n * @param listener - The listener function that gets removed.\n */\n removeEventListener<T extends keyof EventMap>(type: T, listener: (event: EventMap[T]) => void): this {\n if (this._listeners === undefined) return this;\n if (this._listeners[type] === undefined) return this;\n const listeners = this._listeners[type].filter((x) => x !== listener);\n this._listeners[type] = listeners.length === 0 ? undefined : listeners;\n return this;\n }\n\n /**\n * If `type` is specified, removes all registered listeners for type, otherwise removes all\n * registered listeners.\n *\n * @param type - The type of the listener that gets removed.\n */\n removeAllListeners<T extends keyof EventMap>(type?: T): this {\n if (type) this._listeners[type] = undefined;\n else this._listeners = undefined;\n return this;\n }\n\n /**\n * Fires the event. Calls each of the listeners registered for the event type `event.type`,\n * in the order they were registered.\n *\n * @param event - The event that gets fired.\n */\n emitEvent<T extends keyof EventMap>(event: Event<Extract<T, string>> & EventMap[T]): boolean {\n if (this._listeners === undefined) return false;\n if (this._listeners[event.type] === undefined) return false;\n const invoke = this._listeners[event.type].slice();\n invoke.forEach((listener) => listener.call(this, event));\n return true;\n }\n\n // Node.js style, to emit custom events\n\n /**\n * Alias to {@link EventEmitter2.addEventListener()}\n */\n on(type: string, listener: (event: any) => void): this {\n return this.addEventListener(type as any, listener as any);\n }\n\n /**\n * Alias to {@link EventEmitter2.removeEventListener()}.\n */\n off(type: string, listener: (event: any) => void): this {\n return this.removeEventListener(type as any, listener as any);\n }\n\n /**\n * Alias to {@link EventEmitter2.emitEvent()}.\n */\n emit(event: string | object, ...args: any[]): boolean {\n if (typeof event === \"string\") return this.emitEvent({ type: event, args } as any);\n else if (typeof event === \"object\") return this.emitEvent(event as any);\n else return false;\n }\n}\n"],"names":[],"mappings":";;;;;;IAAA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IAuBA;;IAEG;UACU,aAAa,CAAA;IAA1B,IAAA,WAAA,GAAA;YACU,IAAU,CAAA,UAAA,GAAG,SAAS,CAAC;SA+EhC;IA7EC;;;;;IAKG;QACH,gBAAgB,CAA2B,IAAO,EAAE,QAAsC,EAAA;IACxF,QAAA,IAAI,IAAI,CAAC,UAAU,KAAK,SAAS;IAAE,YAAA,IAAI,CAAC,UAAU,GAAG,EAAE,CAAC;IACxD,QAAA,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,KAAK,SAAS;IAAE,YAAA,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,EAAE,C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AAC,CAAC,QAAQ,KAAK,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;IACzD,QAAA,OAAO,IAAI,CAAC;SACb;;IAID;;IAEG;QACH,EAAE,CAAC,IAAY,EAAE,QAA8B,EAAA;YAC7C,OAAO,IAAI,CAAC,gBAAgB,CAAC,IAAW,EAAE,QAAe,CAAC,CAAC;SAC5D;IAED;;IAEG;QACH,GAAG,CAAC,IAAY,EAAE,QAA8B,EAAA;YAC9C,OAAO,IAAI,CAAC,mBAAmB,CAAC,IAAW,EAAE,QAAe,CAAC,CAAC;SAC/D;IAED;;IAEG;IACH,IAAA,IAAI,CAAC,KAAsB,EAAE,GAAG,IAAW,EAAA;YACzC,IAAI,OAAO,KAAK,KAAK,QAAQ;IAAE,YAAA,OAAO,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAS,CAAC,CAAC;iBAC9E,IAAI,OAAO,KAAK,KAAK,QAAQ;IAAE,YAAA,OAAO,IAAI,CAAC,SAAS,CAAC,KAAY,CAAC,CAAC;;IACnE,YAAA,OAAO,KAAK,CAAC;SACnB;IACF;;;;;;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"eventemitter2.module.js","sources":["../src/index.ts"],"sourcesContent":["///////////////////////////////////////////////////////////////////////////////\n// Copyright (C) 2002-2021, Open Design Alliance (the \"Alliance\").\n// All rights reserved.\n//\n// This software and its documentation and related materials are owned by\n// the Alliance. The software may only be incorporated into application\n// programs owned by members of the Alliance, subject to a signed\n// Membership Agreement and Supplemental Software License Agreement with the\n// Alliance. The structure and organization of this software are the valuable\n// trade secrets of the Alliance and its suppliers. The software is also\n// protected by copyright law and international treaty provisions. Application\n// programs incorporating this software must include the following statement\n// with their copyright notices:\n//\n// This application incorporates Open Design Alliance software pursuant to a\n// license agreement with Open Design Alliance.\n// Open Design Alliance Copyright (C) 2002-2021 by Open Design Alliance.\n// All rights reserved.\n//\n// By use of this software, its documentation or related materials, you\n// acknowledge and accept the above terms.\n///////////////////////////////////////////////////////////////////////////////\n\nexport interface IEvent {\n type: string;\n}\n\nexport interface IEventEmitter {\n addEventListener(type: string, listener: (event: IEvent) => void): this;\n removeEventListener(type: string, listener: (event: IEvent) => void): this;\n removeAllListeners(type?: string): this;\n emitEvent(event: IEvent): boolean;\n on(type: string, listener: (event:
|
|
1
|
+
{"version":3,"file":"eventemitter2.module.js","sources":["../src/index.ts"],"sourcesContent":["///////////////////////////////////////////////////////////////////////////////\n// Copyright (C) 2002-2021, Open Design Alliance (the \"Alliance\").\n// All rights reserved.\n//\n// This software and its documentation and related materials are owned by\n// the Alliance. The software may only be incorporated into application\n// programs owned by members of the Alliance, subject to a signed\n// Membership Agreement and Supplemental Software License Agreement with the\n// Alliance. The structure and organization of this software are the valuable\n// trade secrets of the Alliance and its suppliers. The software is also\n// protected by copyright law and international treaty provisions. Application\n// programs incorporating this software must include the following statement\n// with their copyright notices:\n//\n// This application incorporates Open Design Alliance software pursuant to a\n// license agreement with Open Design Alliance.\n// Open Design Alliance Copyright (C) 2002-2021 by Open Design Alliance.\n// All rights reserved.\n//\n// By use of this software, its documentation or related materials, you\n// acknowledge and accept the above terms.\n///////////////////////////////////////////////////////////////////////////////\n\nexport interface IEvent {\n type: string;\n}\n\nexport interface IEventEmitter {\n addEventListener(type: string, listener: (event: IEvent) => void): this;\n removeEventListener(type: string, listener: (event: IEvent) => void): this;\n removeAllListeners(type?: string): this;\n emitEvent(event: IEvent): boolean;\n on(type: string, listener: (event: any) => void): this;\n off(type: string, listener: (event: any) => void): this;\n emit(event: string | object, ...args: any[]): boolean;\n}\n\n/**\n * The minimal basic Event that can be emitted by a {@link EventEmitter2}.\n */\nexport interface Event<T extends string = string> extends IEvent {\n type: T;\n}\n\n/**\n * Event emitter for custom objects.\n */\nexport class EventEmitter2<EventMap extends Record<string, any> = Record<string, any>> implements IEventEmitter {\n private _listeners = undefined;\n\n /**\n * Registers a new listener for an event type.\n *\n * @param type - The type of event to listen to.\n * @param listener - The function that gets called when the event is fired.\n */\n addEventListener<T extends keyof EventMap>(type: T, listener: (event: EventMap[T]) => void): this {\n if (this._listeners === undefined) this._listeners = {};\n if (this._listeners[type] === undefined) this._listeners[type] = [];\n this._listeners[type].push(listener);\n return this;\n }\n\n /**\n * Removes the listener from an event type.\n *\n * @param type - The type of the listener that gets removed.\n * @param listener - The listener function that gets removed.\n */\n removeEventListener<T extends keyof EventMap>(type: T, listener: (event: EventMap[T]) => void): this {\n if (this._listeners === undefined) return this;\n if (this._listeners[type] === undefined) return this;\n const listeners = this._listeners[type].filter((x) => x !== listener);\n this._listeners[type] = listeners.length === 0 ? undefined : listeners;\n return this;\n }\n\n /**\n * If `type` is specified, removes all registered listeners for type, otherwise removes all\n * registered listeners.\n *\n * @param type - The type of the listener that gets removed.\n */\n removeAllListeners<T extends keyof EventMap>(type?: T): this {\n if (type) this._listeners[type] = undefined;\n else this._listeners = undefined;\n return this;\n }\n\n /**\n * Fires the event. Calls each of the listeners registered for the event type `event.type`,\n * in the order they were registered.\n *\n * @param event - The event that gets fired.\n */\n emitEvent<T extends keyof EventMap>(event: Event<Extract<T, string>> & EventMap[T]): boolean {\n if (this._listeners === undefined) return false;\n if (this._listeners[event.type] === undefined) return false;\n const invoke = this._listeners[event.type].slice();\n invoke.forEach((listener) => listener.call(this, event));\n return true;\n }\n\n // Node.js style, to emit custom events\n\n /**\n * Alias to {@link EventEmitter2.addEventListener()}\n */\n on(type: string, listener: (event: any) => void): this {\n return this.addEventListener(type as any, listener as any);\n }\n\n /**\n * Alias to {@link EventEmitter2.removeEventListener()}.\n */\n off(type: string, listener: (event: any) => void): this {\n return this.removeEventListener(type as any, listener as any);\n }\n\n /**\n * Alias to {@link EventEmitter2.emitEvent()}.\n */\n emit(event: string | object, ...args: any[]): boolean {\n if (typeof event === \"string\") return this.emitEvent({ type: event, args } as any);\n else if (typeof event === \"object\") return this.emitEvent(event as any);\n else return false;\n }\n}\n"],"names":["EventEmitter2","constructor","this","_listeners","undefined","addEventListener","type","listener","push","removeEventListener","listeners","filter","x","length","removeAllListeners","emitEvent","event","invoke","slice","forEach","call","on","off","emit","args"],"mappings":"MA+CaA;IAAb,WAAAC;QACUC,KAAUC,aAAGC;AA+EtB;IAvEC,gBAAAC,CAA2CC,MAASC;QAClD,IAAIL,KAAKC,eAAeC,WAAWF,KAAKC,aAAa;QACrD,IAAID,KAAKC,WAAWG,UAAUF,WAAWF,KAAKC,WAAWG,QAAQ;QACjEJ,KAAKC,WAAWG,MAAME,KAAKD;QAC3B,OAAOL;AACR;IAQD,mBAAAO,CAA8CH,MAASC;QACrD,IAAIL,KAAKC,eAAeC,WAAW,OAAOF;QAC1C,IAAIA,KAAKC,WAAWG,UAAUF,WAAW,OAAOF;QAChD,MAAMQ,YAAYR,KAAKC,WAAWG,MAAMK,QAAQC,KAAMA,MAAML;QAC5DL,KAAKC,WAAWG,QAAQI,UAAUG,WAAW,IAAIT,YAAYM;QAC7D,OAAOR;AACR;IAQD,kBAAAY,CAA6CR;QAC3C,IAAIA,MAAMJ,KAAKC,WAAWG,QAAQF,gBAC7BF,KAAKC,aAAaC;QACvB,OAAOF;AACR;IAQD,SAAAa,CAAoCC;QAClC,IAAId,KAAKC,eAAeC,WAAW,OAAO;QAC1C,IAAIF,KAAKC,WAAWa,MAAMV,UAAUF,WAAW,OAAO;QACtD,MAAMa,SAASf,KAAKC,WAAWa,MAAMV,MAAMY;QAC3CD,OAAOE,SAASZ,YAAaA,SAASa,KAAKlB,MAAMc;QACjD,OAAO;AACR;IAOD,EAAAK,CAAGf,MAAcC;QACf,OAAOL,KAAKG,iBAAiBC,MAAaC;AAC3C;IAKD,GAAAe,CAAIhB,MAAcC;QAChB,OAAOL,KAAKO,oBAAoBH,MAAaC;AAC9C;IAKD,IAAAgB,CAAKP,UAA2BQ;QAC9B,WAAWR,UAAU,UAAU,OAAOd,KAAKa,UAAU;YAAET,MAAMU;YAAOQ;iBAC/D,WAAWR,UAAU,UAAU,OAAOd,KAAKa,UAAUC,aACrD,OAAO;AACb;;;"}
|
package/lib/index.d.ts
CHANGED
|
@@ -6,8 +6,8 @@ export interface IEventEmitter {
|
|
|
6
6
|
removeEventListener(type: string, listener: (event: IEvent) => void): this;
|
|
7
7
|
removeAllListeners(type?: string): this;
|
|
8
8
|
emitEvent(event: IEvent): boolean;
|
|
9
|
-
on(type: string, listener: (event:
|
|
10
|
-
off(type: string, listener: (event:
|
|
9
|
+
on(type: string, listener: (event: any) => void): this;
|
|
10
|
+
off(type: string, listener: (event: any) => void): this;
|
|
11
11
|
emit(event: string | object, ...args: any[]): boolean;
|
|
12
12
|
}
|
|
13
13
|
/**
|
|
@@ -52,11 +52,11 @@ export declare class EventEmitter2<EventMap extends Record<string, any> = Record
|
|
|
52
52
|
/**
|
|
53
53
|
* Alias to {@link EventEmitter2.addEventListener()}
|
|
54
54
|
*/
|
|
55
|
-
on(type: string, listener: (event:
|
|
55
|
+
on(type: string, listener: (event: any) => void): this;
|
|
56
56
|
/**
|
|
57
57
|
* Alias to {@link EventEmitter2.removeEventListener()}.
|
|
58
58
|
*/
|
|
59
|
-
off(type: string, listener: (event:
|
|
59
|
+
off(type: string, listener: (event: any) => void): this;
|
|
60
60
|
/**
|
|
61
61
|
* Alias to {@link EventEmitter2.emitEvent()}.
|
|
62
62
|
*/
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -30,8 +30,8 @@ export interface IEventEmitter {
|
|
|
30
30
|
removeEventListener(type: string, listener: (event: IEvent) => void): this;
|
|
31
31
|
removeAllListeners(type?: string): this;
|
|
32
32
|
emitEvent(event: IEvent): boolean;
|
|
33
|
-
on(type: string, listener: (event:
|
|
34
|
-
off(type: string, listener: (event:
|
|
33
|
+
on(type: string, listener: (event: any) => void): this;
|
|
34
|
+
off(type: string, listener: (event: any) => void): this;
|
|
35
35
|
emit(event: string | object, ...args: any[]): boolean;
|
|
36
36
|
}
|
|
37
37
|
|
|
@@ -106,14 +106,14 @@ export class EventEmitter2<EventMap extends Record<string, any> = Record<string,
|
|
|
106
106
|
/**
|
|
107
107
|
* Alias to {@link EventEmitter2.addEventListener()}
|
|
108
108
|
*/
|
|
109
|
-
on(type: string, listener: (event:
|
|
109
|
+
on(type: string, listener: (event: any) => void): this {
|
|
110
110
|
return this.addEventListener(type as any, listener as any);
|
|
111
111
|
}
|
|
112
112
|
|
|
113
113
|
/**
|
|
114
114
|
* Alias to {@link EventEmitter2.removeEventListener()}.
|
|
115
115
|
*/
|
|
116
|
-
off(type: string, listener: (event:
|
|
116
|
+
off(type: string, listener: (event: any) => void): this {
|
|
117
117
|
return this.removeEventListener(type as any, listener as any);
|
|
118
118
|
}
|
|
119
119
|
|