@creejs/commons-events 2.0.0 → 2.0.2
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/index.js +2 -2
- package/lib/constants.js +2 -4
- package/lib/event-emitter.js +14 -12
- package/lib/event.js +9 -7
- package/lib/index.js +3 -5
- package/lib/listener.js +8 -8
- package/package.json +37 -5
- package/types/constants.d.ts +4 -0
- package/types/event-emitter.d.ts +6 -6
- package/types/event.d.ts +6 -6
- package/types/index.d.ts +2 -1
- package/types/listener.d.ts +11 -7
package/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
export { default } from './lib/index.js'
|
|
2
|
+
export * from './lib/index.js'
|
package/lib/constants.js
CHANGED
package/lib/event-emitter.js
CHANGED
|
@@ -1,20 +1,22 @@
|
|
|
1
|
-
'use strict'
|
|
2
1
|
// 3rd
|
|
3
2
|
// internal
|
|
4
|
-
|
|
5
|
-
TypeUtils: { isNil },
|
|
6
|
-
TypeAssert: {
|
|
7
|
-
assertString, assertFunction, assertNumber,
|
|
8
|
-
assertStringOrSymbol, assertNotNil
|
|
9
|
-
}
|
|
10
|
-
} = require('@creejs/commons-lang')
|
|
3
|
+
import { TypeUtils, TypeAssert } from '@creejs/commons-lang'
|
|
11
4
|
|
|
12
5
|
// owned
|
|
13
|
-
|
|
6
|
+
import Event from './event.js'
|
|
14
7
|
// eslint-disable-next-line no-unused-vars
|
|
15
|
-
|
|
8
|
+
import Listener from './listener.js'
|
|
16
9
|
|
|
17
10
|
// module vars
|
|
11
|
+
const { isNil } = TypeUtils
|
|
12
|
+
const {
|
|
13
|
+
assertString, assertFunction, assertNumber,
|
|
14
|
+
assertStringOrSymbol, assertNotNil
|
|
15
|
+
} = TypeAssert
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* methods allowed to mixin other objects
|
|
19
|
+
*/
|
|
18
20
|
const MixinMethods = [
|
|
19
21
|
'on', 'once', 'addListener', 'prependListener', 'prependOnceListener',
|
|
20
22
|
'off', 'offAll', 'offOwner', 'removeAllListeners', 'removeListener',
|
|
@@ -29,7 +31,7 @@ let DefaultMaxListeners = 10
|
|
|
29
31
|
* * Operation via "owner"
|
|
30
32
|
* * Duplicate listeners are filtered out. Only unique One kept.
|
|
31
33
|
*/
|
|
32
|
-
class EventEmitter {
|
|
34
|
+
export default class EventEmitter {
|
|
33
35
|
/**
|
|
34
36
|
* Mixes EventEmitter methods into the given object.
|
|
35
37
|
* @template T
|
|
@@ -368,4 +370,4 @@ class EventEmitter {
|
|
|
368
370
|
}
|
|
369
371
|
}
|
|
370
372
|
|
|
371
|
-
|
|
373
|
+
export { EventEmitter as EventEmitterType }
|
package/lib/event.js
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
'use strict'
|
|
2
1
|
// 3rd
|
|
3
2
|
// internal
|
|
4
|
-
|
|
3
|
+
import { TypeUtils, TypeAssert } from '@creejs/commons-lang'
|
|
4
|
+
|
|
5
|
+
// owned
|
|
5
6
|
// eslint-disable-next-line no-unused-vars
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const { assertFunction } = require('@creejs/commons-lang/lib/type-assert')
|
|
7
|
+
import Listener from './listener.js'
|
|
8
|
+
import { DefaultOwner } from './constants.js'
|
|
9
9
|
|
|
10
10
|
// module vars
|
|
11
|
+
const { isFunction, isNil } = TypeUtils
|
|
12
|
+
const { assertStringOrSymbol, assertFunction } = TypeAssert
|
|
11
13
|
|
|
12
14
|
/**
|
|
13
15
|
* An Event definition
|
|
@@ -16,7 +18,7 @@ const { assertFunction } = require('@creejs/commons-lang/lib/type-assert')
|
|
|
16
18
|
* 2. one listener may belong to multiple owners
|
|
17
19
|
* 3. one owner may have multiple listeners
|
|
18
20
|
*/
|
|
19
|
-
class Event {
|
|
21
|
+
export default class Event {
|
|
20
22
|
static get DefaultOwner () {
|
|
21
23
|
return DefaultOwner
|
|
22
24
|
}
|
|
@@ -357,4 +359,4 @@ class Event {
|
|
|
357
359
|
}
|
|
358
360
|
}
|
|
359
361
|
|
|
360
|
-
|
|
362
|
+
export { Event as EventType }
|
package/lib/index.js
CHANGED
package/lib/listener.js
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
|
-
'use strict'
|
|
2
1
|
// 3rd
|
|
3
2
|
// internal
|
|
4
|
-
|
|
3
|
+
import { TypeAssert } from '@creejs/commons-lang'
|
|
5
4
|
|
|
6
5
|
// owned
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
import { DefaultOwner } from './constants.js'
|
|
7
|
+
|
|
8
|
+
// module vars
|
|
9
|
+
const { assertFunction, assertNotNil } = TypeAssert
|
|
10
10
|
/**
|
|
11
11
|
* Wraps a function to be called when an event is fired.
|
|
12
|
+
* @typedef {import('./event.js').default} Event
|
|
12
13
|
* @class Listener
|
|
13
14
|
*/
|
|
14
|
-
class Listener {
|
|
15
|
+
export default class Listener {
|
|
15
16
|
/**
|
|
16
17
|
* @param {Event} event
|
|
17
18
|
* @param {function} callback - The function to be called when event is fired
|
|
@@ -89,5 +90,4 @@ class Listener {
|
|
|
89
90
|
return this.invoke(...args)
|
|
90
91
|
}
|
|
91
92
|
}
|
|
92
|
-
|
|
93
|
-
module.exports = Listener
|
|
93
|
+
export { Listener as ListenerType }
|
package/package.json
CHANGED
|
@@ -1,30 +1,62 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@creejs/commons-events",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"description": "Commons EventEmitter",
|
|
5
|
-
"
|
|
5
|
+
"keywords": [
|
|
6
|
+
"commons",
|
|
7
|
+
"creejs",
|
|
8
|
+
"events",
|
|
9
|
+
"event",
|
|
10
|
+
"emitter",
|
|
11
|
+
"EventEmitter"
|
|
12
|
+
],
|
|
6
13
|
"private": false,
|
|
14
|
+
"type": "module",
|
|
7
15
|
"files": [
|
|
8
16
|
"index.js",
|
|
9
17
|
"lib/",
|
|
10
18
|
"types/",
|
|
11
19
|
"README.md"
|
|
12
20
|
],
|
|
21
|
+
"types": "types/index.d.ts",
|
|
22
|
+
"main": "./dist/esm/index-min.js",
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"import": {
|
|
26
|
+
"development": "./dist/esm/index-dev.js",
|
|
27
|
+
"production": "./dist/esm/index-min.js",
|
|
28
|
+
"default": "./dist/esm/index-min.js"
|
|
29
|
+
},
|
|
30
|
+
"require": {
|
|
31
|
+
"development": "./dist/cjs/index-dev.cjs",
|
|
32
|
+
"production": "./dist/cjs/index-min.cjs",
|
|
33
|
+
"default": "./dist/cjs/index-min.cjs"
|
|
34
|
+
},
|
|
35
|
+
"browser": {
|
|
36
|
+
"development": "./dist/umd/index-dev.js",
|
|
37
|
+
"production": "./dist/umd/index-min.js",
|
|
38
|
+
"default": "./dist/cjs/index-min.js"
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
},
|
|
13
42
|
"publishConfig": {
|
|
14
43
|
"access": "public"
|
|
15
44
|
},
|
|
16
|
-
"types": "types/index.d.ts",
|
|
17
45
|
"repository": {
|
|
18
46
|
"type": "git",
|
|
19
47
|
"url": "git+https://github.com/frameworkee/commons.git"
|
|
20
48
|
},
|
|
21
49
|
"scripts": {
|
|
22
50
|
"dts": "tsc",
|
|
23
|
-
"generate-docs": "../../node_modules/.bin/jsdoc -c ./jsdoc.json"
|
|
51
|
+
"generate-docs": "../../node_modules/.bin/jsdoc -c ./jsdoc.json",
|
|
52
|
+
"clean": "rm -rf dist && rm -rf types",
|
|
53
|
+
"build": "npm run clean && npm run dts && rollup -c",
|
|
54
|
+
"prepublishOnly": "npm run build",
|
|
55
|
+
"publish": "npm run prepublishOnly && npm publish"
|
|
24
56
|
},
|
|
25
57
|
"author": "rodney.vin@gmail.com",
|
|
26
58
|
"license": "Apache-2.0",
|
|
27
59
|
"dependencies": {
|
|
28
|
-
"@creejs/commons-lang": "^2.0.
|
|
60
|
+
"@creejs/commons-lang": "^2.0.1"
|
|
29
61
|
}
|
|
30
62
|
}
|
package/types/constants.d.ts
CHANGED
package/types/event-emitter.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export = EventEmitter;
|
|
2
1
|
/**
|
|
3
2
|
* 1. An EventEmitter follows the API of NodeJS EventEmitter.
|
|
4
3
|
* 2. Enhancement:
|
|
@@ -6,7 +5,7 @@ export = EventEmitter;
|
|
|
6
5
|
* * Operation via "owner"
|
|
7
6
|
* * Duplicate listeners are filtered out. Only unique One kept.
|
|
8
7
|
*/
|
|
9
|
-
|
|
8
|
+
export default class EventEmitter {
|
|
10
9
|
/**
|
|
11
10
|
* Mixes EventEmitter methods into the given object.
|
|
12
11
|
* @template T
|
|
@@ -14,7 +13,7 @@ declare class EventEmitter {
|
|
|
14
13
|
* @returns {T} The modified object with EventEmitter methods.
|
|
15
14
|
*/
|
|
16
15
|
static mixin<T>(obj: T): T;
|
|
17
|
-
static set defaultMaxListeners(
|
|
16
|
+
static set defaultMaxListeners(arg: number);
|
|
18
17
|
static get defaultMaxListeners(): number;
|
|
19
18
|
/**
|
|
20
19
|
* @type {Map<string|Symbol, Event>}
|
|
@@ -68,7 +67,7 @@ declare class EventEmitter {
|
|
|
68
67
|
* @param {function} [listener] - Optional specific listener to count
|
|
69
68
|
* @returns {number} The number of listeners for the event
|
|
70
69
|
*/
|
|
71
|
-
listenerCount(eventName: string | Symbol, listener?: Function): number;
|
|
70
|
+
listenerCount(eventName: string | Symbol, listener?: Function | undefined): number;
|
|
72
71
|
/**
|
|
73
72
|
* Returns a copy of the array of listeners for the event named eventName.
|
|
74
73
|
* 1. if a callback function added multiple times, it will be returned multiple times.
|
|
@@ -174,5 +173,6 @@ declare class EventEmitter {
|
|
|
174
173
|
*/
|
|
175
174
|
hasOwner(owner: Object): boolean;
|
|
176
175
|
}
|
|
177
|
-
|
|
178
|
-
import
|
|
176
|
+
export { EventEmitter as EventEmitterType };
|
|
177
|
+
import Event from "./event.js";
|
|
178
|
+
import Listener from "./listener.js";
|
package/types/event.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export = Event;
|
|
2
1
|
/**
|
|
3
2
|
* An Event definition
|
|
4
3
|
* 1. listeners are grouped by owner
|
|
@@ -6,7 +5,7 @@ export = Event;
|
|
|
6
5
|
* 2. one listener may belong to multiple owners
|
|
7
6
|
* 3. one owner may have multiple listeners
|
|
8
7
|
*/
|
|
9
|
-
|
|
8
|
+
export default class Event {
|
|
10
9
|
static get DefaultOwner(): string;
|
|
11
10
|
/**
|
|
12
11
|
* Creates a new Event instance with the specified name.
|
|
@@ -54,7 +53,7 @@ declare class Event {
|
|
|
54
53
|
* @param {Function} [callback] - The callback function to count
|
|
55
54
|
* @returns {number}
|
|
56
55
|
*/
|
|
57
|
-
listenerCount(callback?: Function): number;
|
|
56
|
+
listenerCount(callback?: Function | undefined): number;
|
|
58
57
|
/**
|
|
59
58
|
* Returns a shallow copy of the registered callbacks array.
|
|
60
59
|
* if one callback function is added multiple times, it will be returned multiple times.
|
|
@@ -102,7 +101,7 @@ declare class Event {
|
|
|
102
101
|
* @param {Object} [owner] - The object that owns the callback (used for binding `this` context).
|
|
103
102
|
* @returns {boolean}
|
|
104
103
|
*/
|
|
105
|
-
addOnceListener(callback: Function, owner?: Object): boolean;
|
|
104
|
+
addOnceListener(callback: Function, owner?: Object | undefined): boolean;
|
|
106
105
|
/**
|
|
107
106
|
* Adds a one-time event listener that will be automatically removed after being triggered once.
|
|
108
107
|
* The listener will only be triggered if the event is pretended (simulated).
|
|
@@ -120,7 +119,7 @@ declare class Event {
|
|
|
120
119
|
* @returns {boolean} Returns true if listener was added successfully, false if callback is nil or duplicate
|
|
121
120
|
* @protected
|
|
122
121
|
*/
|
|
123
|
-
protected _addListener(callback: Function, owner?: any, isOnce?: boolean, isPrepend?: boolean): boolean;
|
|
122
|
+
protected _addListener(callback: Function, owner?: any, isOnce?: boolean | undefined, isPrepend?: boolean | undefined): boolean;
|
|
124
123
|
/**
|
|
125
124
|
* Removes a callback
|
|
126
125
|
* @param {Function} callback - The callback function to remove.
|
|
@@ -139,4 +138,5 @@ declare class Event {
|
|
|
139
138
|
*/
|
|
140
139
|
removeAllListeners(owner?: any): this;
|
|
141
140
|
}
|
|
142
|
-
|
|
141
|
+
export { Event as EventType };
|
|
142
|
+
import Listener from "./listener.js";
|
package/types/index.d.ts
CHANGED
package/types/listener.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
export = Listener;
|
|
2
1
|
/**
|
|
3
2
|
* Wraps a function to be called when an event is fired.
|
|
3
|
+
* @typedef {import('./event.js').default} Event
|
|
4
4
|
* @class Listener
|
|
5
5
|
*/
|
|
6
|
-
|
|
6
|
+
export default class Listener {
|
|
7
7
|
/**
|
|
8
8
|
* @param {Event} event
|
|
9
9
|
* @param {function} callback - The function to be called when event is fired
|
|
10
10
|
* @param {boolean} [isOnce=false] - is a one time listener?
|
|
11
11
|
*/
|
|
12
|
-
constructor(event: Event, callback: Function, isOnce?: boolean);
|
|
13
|
-
_event:
|
|
12
|
+
constructor(event: Event, callback: Function, isOnce?: boolean | undefined);
|
|
13
|
+
_event: import("./event.js").default;
|
|
14
14
|
_callback: Function;
|
|
15
15
|
_isOnce: boolean;
|
|
16
16
|
_owner: any;
|
|
@@ -18,9 +18,9 @@ declare class Listener {
|
|
|
18
18
|
* Sets the owner of this listener.
|
|
19
19
|
* @param {*} owner - The owner object to be associated with this listener.
|
|
20
20
|
*/
|
|
21
|
-
set owner(
|
|
21
|
+
set owner(arg: any);
|
|
22
22
|
get owner(): any;
|
|
23
|
-
get event():
|
|
23
|
+
get event(): import("./event.js").default;
|
|
24
24
|
get isOnce(): boolean;
|
|
25
25
|
/**
|
|
26
26
|
* Checks if the provided function is the same as the listener's wrapped function.
|
|
@@ -43,4 +43,8 @@ declare class Listener {
|
|
|
43
43
|
*/
|
|
44
44
|
listener(...args: any[]): any;
|
|
45
45
|
}
|
|
46
|
-
|
|
46
|
+
export { Listener as ListenerType };
|
|
47
|
+
/**
|
|
48
|
+
* Wraps a function to be called when an event is fired.
|
|
49
|
+
*/
|
|
50
|
+
export type Event = import('./event.js').default;
|