@inweb/eventemitter2 25.3.13

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/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (C) 2002-2021, Open Design Alliance (the "Alliance").
2
+ All rights reserved.
3
+
4
+ This software and its documentation and related materials are owned by
5
+ the Alliance. The software may only be incorporated into application
6
+ programs owned by members of the Alliance, subject to a signed
7
+ Membership Agreement and Supplemental Software License Agreement with the
8
+ Alliance. The structure and organization of this software are the valuable
9
+ trade secrets of the Alliance and its suppliers. The software is also
10
+ protected by copyright law and international treaty provisions. Application
11
+ programs incorporating this software must include the following statement
12
+ with their copyright notices:
13
+
14
+ This application incorporates Open Design Alliance software pursuant to a
15
+ license agreement with Open Design Alliance.
16
+ Open Design Alliance Copyright (C) 2002-2021 by Open Design Alliance.
17
+ All rights reserved.
18
+
19
+ By use of this software, its documentation or related materials, you
20
+ acknowledge and accept the above terms.
package/README.md ADDED
@@ -0,0 +1,7 @@
1
+ # EventEmitter2
2
+
3
+ JavaScript event emitter for the [inWEB Open Cloud](https://www.opendesign.com/products/open-cloud) platform.
4
+
5
+ ## Copyright and license
6
+
7
+ Code and documentation copyright 2002-2024 the [Open Design Alliance](https://opendesign.com). Code is distributed under a proprietary license, see [LICENSE](./LICENSE) for more information.
@@ -0,0 +1,124 @@
1
+ (function (global, factory) {
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3
+ typeof define === 'function' && define.amd ? define(['exports'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ODA = global.ODA || {}));
5
+ })(this, (function (exports) { 'use strict';
6
+
7
+ ///////////////////////////////////////////////////////////////////////////////
8
+ // Copyright (C) 2002-2021, Open Design Alliance (the "Alliance").
9
+ // All rights reserved.
10
+ //
11
+ // This software and its documentation and related materials are owned by
12
+ // the Alliance. The software may only be incorporated into application
13
+ // programs owned by members of the Alliance, subject to a signed
14
+ // Membership Agreement and Supplemental Software License Agreement with the
15
+ // Alliance. The structure and organization of this software are the valuable
16
+ // trade secrets of the Alliance and its suppliers. The software is also
17
+ // protected by copyright law and international treaty provisions. Application
18
+ // programs incorporating this software must include the following statement
19
+ // with their copyright notices:
20
+ //
21
+ // This application incorporates Open Design Alliance software pursuant to a
22
+ // license agreement with Open Design Alliance.
23
+ // Open Design Alliance Copyright (C) 2002-2021 by Open Design Alliance.
24
+ // All rights reserved.
25
+ //
26
+ // By use of this software, its documentation or related materials, you
27
+ // acknowledge and accept the above terms.
28
+ ///////////////////////////////////////////////////////////////////////////////
29
+ /**
30
+ * Event emitter for custom objects.
31
+ */
32
+ class EventEmitter2 {
33
+ constructor() {
34
+ this._listeners = undefined;
35
+ }
36
+ /**
37
+ * Registers a new listener for an event type.
38
+ *
39
+ * @param type - The type of event to listen to.
40
+ * @param listener - The function that gets called when the event is fired.
41
+ */
42
+ addEventListener(type, listener) {
43
+ if (this._listeners === undefined)
44
+ this._listeners = {};
45
+ if (this._listeners[type] === undefined)
46
+ this._listeners[type] = [];
47
+ this._listeners[type].push(listener);
48
+ return this;
49
+ }
50
+ /**
51
+ * Removes the listener from an event type.
52
+ *
53
+ * @param type - The type of the listener that gets removed.
54
+ * @param listener - The listener function that gets removed.
55
+ */
56
+ removeEventListener(type, listener) {
57
+ if (this._listeners === undefined)
58
+ return this;
59
+ if (this._listeners[type] === undefined)
60
+ return this;
61
+ const listeners = this._listeners[type].filter((x) => x !== listener);
62
+ this._listeners[type] = listeners.length === 0 ? undefined : listeners;
63
+ return this;
64
+ }
65
+ /**
66
+ * If `type` is specified, removes all registered listeners for type, otherwise removes all
67
+ * registered listeners.
68
+ *
69
+ * @param type - The type of the listener that gets removed.
70
+ */
71
+ removeAllListeners(type) {
72
+ if (type)
73
+ this._listeners[type] = undefined;
74
+ else
75
+ this._listeners = undefined;
76
+ return this;
77
+ }
78
+ /**
79
+ * Fires the event. Calls each of the listeners registered for the event type `event.type`,
80
+ * in the order they were registered.
81
+ *
82
+ * @param event - The event that gets fired.
83
+ */
84
+ emitEvent(event) {
85
+ if (this._listeners === undefined)
86
+ return false;
87
+ if (this._listeners[event.type] === undefined)
88
+ return false;
89
+ const invoke = this._listeners[event.type].slice();
90
+ invoke.forEach((listener) => listener.call(this, event));
91
+ return true;
92
+ }
93
+ // Node.js style, to emit custom events
94
+ /**
95
+ * Alias to {@link EventEmitter2.addEventListener()}
96
+ */
97
+ on(type, listener) {
98
+ return this.addEventListener(type, listener);
99
+ }
100
+ /**
101
+ * Alias to {@link EventEmitter2.removeEventListener()}.
102
+ */
103
+ off(type, listener) {
104
+ return this.removeEventListener(type, listener);
105
+ }
106
+ /**
107
+ * Alias to {@link EventEmitter2.emitEvent()}.
108
+ */
109
+ emit(event, ...args) {
110
+ if (typeof event === "string")
111
+ return this.emitEvent({ type: event, args });
112
+ else if (typeof event === "object")
113
+ return this.emitEvent(event);
114
+ else
115
+ return false;
116
+ }
117
+ }
118
+
119
+ exports.EventEmitter2 = EventEmitter2;
120
+
121
+ Object.defineProperty(exports, '__esModule', { value: true });
122
+
123
+ }));
124
+ //# sourceMappingURL=eventemitter2.js.map
@@ -0,0 +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: object) => void): this;\n off(type: string, listener: (event: object) => 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: object) => 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: object) => 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":"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"}
@@ -0,0 +1 @@
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ODA=e.ODA||{})}(this,(function(e){"use strict";e.EventEmitter2=class{constructor(){this._listeners=void 0}addEventListener(e,t){return void 0===this._listeners&&(this._listeners={}),void 0===this._listeners[e]&&(this._listeners[e]=[]),this._listeners[e].push(t),this}removeEventListener(e,t){if(void 0===this._listeners)return this;if(void 0===this._listeners[e])return this;const i=this._listeners[e].filter((e=>e!==t));return this._listeners[e]=0===i.length?void 0:i,this}removeAllListeners(e){return e?this._listeners[e]=void 0:this._listeners=void 0,this}emitEvent(e){if(void 0===this._listeners)return!1;if(void 0===this._listeners[e.type])return!1;return this._listeners[e.type].slice().forEach((t=>t.call(this,e))),!0}on(e,t){return this.addEventListener(e,t)}off(e,t){return this.removeEventListener(e,t)}emit(e,...t){return"string"==typeof e?this.emitEvent({type:e,args:t}):"object"==typeof e&&this.emitEvent(e)}},Object.defineProperty(e,"__esModule",{value:!0})}));
@@ -0,0 +1,44 @@
1
+ class EventEmitter2 {
2
+ constructor() {
3
+ this._listeners = undefined;
4
+ }
5
+ addEventListener(type, listener) {
6
+ if (this._listeners === undefined) this._listeners = {};
7
+ if (this._listeners[type] === undefined) this._listeners[type] = [];
8
+ this._listeners[type].push(listener);
9
+ return this;
10
+ }
11
+ removeEventListener(type, listener) {
12
+ if (this._listeners === undefined) return this;
13
+ if (this._listeners[type] === undefined) return this;
14
+ const listeners = this._listeners[type].filter((x => x !== listener));
15
+ this._listeners[type] = listeners.length === 0 ? undefined : listeners;
16
+ return this;
17
+ }
18
+ removeAllListeners(type) {
19
+ if (type) this._listeners[type] = undefined; else this._listeners = undefined;
20
+ return this;
21
+ }
22
+ emitEvent(event) {
23
+ if (this._listeners === undefined) return false;
24
+ if (this._listeners[event.type] === undefined) return false;
25
+ const invoke = this._listeners[event.type].slice();
26
+ invoke.forEach((listener => listener.call(this, event)));
27
+ return true;
28
+ }
29
+ on(type, listener) {
30
+ return this.addEventListener(type, listener);
31
+ }
32
+ off(type, listener) {
33
+ return this.removeEventListener(type, listener);
34
+ }
35
+ emit(event, ...args) {
36
+ if (typeof event === "string") return this.emitEvent({
37
+ type: event,
38
+ args: args
39
+ }); else if (typeof event === "object") return this.emitEvent(event); else return false;
40
+ }
41
+ }
42
+
43
+ export { EventEmitter2 };
44
+ //# sourceMappingURL=eventemitter2.module.js.map
@@ -0,0 +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: object) => void): this;\n off(type: string, listener: (event: object) => 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: object) => 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: object) => 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 ADDED
@@ -0,0 +1,64 @@
1
+ export interface IEvent {
2
+ type: string;
3
+ }
4
+ export interface IEventEmitter {
5
+ addEventListener(type: string, listener: (event: IEvent) => void): this;
6
+ removeEventListener(type: string, listener: (event: IEvent) => void): this;
7
+ removeAllListeners(type?: string): this;
8
+ emitEvent(event: IEvent): boolean;
9
+ on(type: string, listener: (event: object) => void): this;
10
+ off(type: string, listener: (event: object) => void): this;
11
+ emit(event: string | object, ...args: any[]): boolean;
12
+ }
13
+ /**
14
+ * The minimal basic Event that can be emitted by a {@link EventEmitter2}.
15
+ */
16
+ export interface Event<T extends string = string> extends IEvent {
17
+ type: T;
18
+ }
19
+ /**
20
+ * Event emitter for custom objects.
21
+ */
22
+ export declare class EventEmitter2<EventMap extends Record<string, any> = Record<string, any>> implements IEventEmitter {
23
+ private _listeners;
24
+ /**
25
+ * Registers a new listener for an event type.
26
+ *
27
+ * @param type - The type of event to listen to.
28
+ * @param listener - The function that gets called when the event is fired.
29
+ */
30
+ addEventListener<T extends keyof EventMap>(type: T, listener: (event: EventMap[T]) => void): this;
31
+ /**
32
+ * Removes the listener from an event type.
33
+ *
34
+ * @param type - The type of the listener that gets removed.
35
+ * @param listener - The listener function that gets removed.
36
+ */
37
+ removeEventListener<T extends keyof EventMap>(type: T, listener: (event: EventMap[T]) => void): this;
38
+ /**
39
+ * If `type` is specified, removes all registered listeners for type, otherwise removes all
40
+ * registered listeners.
41
+ *
42
+ * @param type - The type of the listener that gets removed.
43
+ */
44
+ removeAllListeners<T extends keyof EventMap>(type?: T): this;
45
+ /**
46
+ * Fires the event. Calls each of the listeners registered for the event type `event.type`,
47
+ * in the order they were registered.
48
+ *
49
+ * @param event - The event that gets fired.
50
+ */
51
+ emitEvent<T extends keyof EventMap>(event: Event<Extract<T, string>> & EventMap[T]): boolean;
52
+ /**
53
+ * Alias to {@link EventEmitter2.addEventListener()}
54
+ */
55
+ on(type: string, listener: (event: object) => void): this;
56
+ /**
57
+ * Alias to {@link EventEmitter2.removeEventListener()}.
58
+ */
59
+ off(type: string, listener: (event: object) => void): this;
60
+ /**
61
+ * Alias to {@link EventEmitter2.emitEvent()}.
62
+ */
63
+ emit(event: string | object, ...args: any[]): boolean;
64
+ }
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "@inweb/eventemitter2",
3
+ "version": "25.3.13",
4
+ "description": "JavaScript event emitter for the inWEB Open Cloud platform.",
5
+ "homepage": "https://cloud.opendesign.com/docs/index.html",
6
+ "license": "SEE LICENSE IN LICENSE",
7
+ "author": "Open Design Alliance",
8
+ "keywords": [
9
+ "opendesign",
10
+ "opencloud",
11
+ "inweb",
12
+ "emitter",
13
+ "events",
14
+ "eventemitter"
15
+ ],
16
+ "sideEffects": false,
17
+ "main": "dist/eventemitter2.js",
18
+ "module": "dist/eventemitter2.module.js",
19
+ "types": "lib/index.d.ts",
20
+ "files": [
21
+ "dist",
22
+ "lib/**/*.d.ts",
23
+ "src"
24
+ ],
25
+ "scripts": {
26
+ "build": "rollup -c rollup.config.js",
27
+ "test": "karma start karma.conf.js"
28
+ }
29
+ }
package/src/index.ts ADDED
@@ -0,0 +1,128 @@
1
+ ///////////////////////////////////////////////////////////////////////////////
2
+ // Copyright (C) 2002-2021, Open Design Alliance (the "Alliance").
3
+ // All rights reserved.
4
+ //
5
+ // This software and its documentation and related materials are owned by
6
+ // the Alliance. The software may only be incorporated into application
7
+ // programs owned by members of the Alliance, subject to a signed
8
+ // Membership Agreement and Supplemental Software License Agreement with the
9
+ // Alliance. The structure and organization of this software are the valuable
10
+ // trade secrets of the Alliance and its suppliers. The software is also
11
+ // protected by copyright law and international treaty provisions. Application
12
+ // programs incorporating this software must include the following statement
13
+ // with their copyright notices:
14
+ //
15
+ // This application incorporates Open Design Alliance software pursuant to a
16
+ // license agreement with Open Design Alliance.
17
+ // Open Design Alliance Copyright (C) 2002-2021 by Open Design Alliance.
18
+ // All rights reserved.
19
+ //
20
+ // By use of this software, its documentation or related materials, you
21
+ // acknowledge and accept the above terms.
22
+ ///////////////////////////////////////////////////////////////////////////////
23
+
24
+ export interface IEvent {
25
+ type: string;
26
+ }
27
+
28
+ export interface IEventEmitter {
29
+ addEventListener(type: string, listener: (event: IEvent) => void): this;
30
+ removeEventListener(type: string, listener: (event: IEvent) => void): this;
31
+ removeAllListeners(type?: string): this;
32
+ emitEvent(event: IEvent): boolean;
33
+ on(type: string, listener: (event: object) => void): this;
34
+ off(type: string, listener: (event: object) => void): this;
35
+ emit(event: string | object, ...args: any[]): boolean;
36
+ }
37
+
38
+ /**
39
+ * The minimal basic Event that can be emitted by a {@link EventEmitter2}.
40
+ */
41
+ export interface Event<T extends string = string> extends IEvent {
42
+ type: T;
43
+ }
44
+
45
+ /**
46
+ * Event emitter for custom objects.
47
+ */
48
+ export class EventEmitter2<EventMap extends Record<string, any> = Record<string, any>> implements IEventEmitter {
49
+ private _listeners = undefined;
50
+
51
+ /**
52
+ * Registers a new listener for an event type.
53
+ *
54
+ * @param type - The type of event to listen to.
55
+ * @param listener - The function that gets called when the event is fired.
56
+ */
57
+ addEventListener<T extends keyof EventMap>(type: T, listener: (event: EventMap[T]) => void): this {
58
+ if (this._listeners === undefined) this._listeners = {};
59
+ if (this._listeners[type] === undefined) this._listeners[type] = [];
60
+ this._listeners[type].push(listener);
61
+ return this;
62
+ }
63
+
64
+ /**
65
+ * Removes the listener from an event type.
66
+ *
67
+ * @param type - The type of the listener that gets removed.
68
+ * @param listener - The listener function that gets removed.
69
+ */
70
+ removeEventListener<T extends keyof EventMap>(type: T, listener: (event: EventMap[T]) => void): this {
71
+ if (this._listeners === undefined) return this;
72
+ if (this._listeners[type] === undefined) return this;
73
+ const listeners = this._listeners[type].filter((x) => x !== listener);
74
+ this._listeners[type] = listeners.length === 0 ? undefined : listeners;
75
+ return this;
76
+ }
77
+
78
+ /**
79
+ * If `type` is specified, removes all registered listeners for type, otherwise removes all
80
+ * registered listeners.
81
+ *
82
+ * @param type - The type of the listener that gets removed.
83
+ */
84
+ removeAllListeners<T extends keyof EventMap>(type?: T): this {
85
+ if (type) this._listeners[type] = undefined;
86
+ else this._listeners = undefined;
87
+ return this;
88
+ }
89
+
90
+ /**
91
+ * Fires the event. Calls each of the listeners registered for the event type `event.type`,
92
+ * in the order they were registered.
93
+ *
94
+ * @param event - The event that gets fired.
95
+ */
96
+ emitEvent<T extends keyof EventMap>(event: Event<Extract<T, string>> & EventMap[T]): boolean {
97
+ if (this._listeners === undefined) return false;
98
+ if (this._listeners[event.type] === undefined) return false;
99
+ const invoke = this._listeners[event.type].slice();
100
+ invoke.forEach((listener) => listener.call(this, event));
101
+ return true;
102
+ }
103
+
104
+ // Node.js style, to emit custom events
105
+
106
+ /**
107
+ * Alias to {@link EventEmitter2.addEventListener()}
108
+ */
109
+ on(type: string, listener: (event: object) => void): this {
110
+ return this.addEventListener(type as any, listener as any);
111
+ }
112
+
113
+ /**
114
+ * Alias to {@link EventEmitter2.removeEventListener()}.
115
+ */
116
+ off(type: string, listener: (event: object) => void): this {
117
+ return this.removeEventListener(type as any, listener as any);
118
+ }
119
+
120
+ /**
121
+ * Alias to {@link EventEmitter2.emitEvent()}.
122
+ */
123
+ emit(event: string | object, ...args: any[]): boolean {
124
+ if (typeof event === "string") return this.emitEvent({ type: event, args } as any);
125
+ else if (typeof event === "object") return this.emitEvent(event as any);
126
+ else return false;
127
+ }
128
+ }