events-ex 2.0.0-alpha.2 → 2.0.0-alpha.3
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/CHANGELOG.md +7 -0
- package/LICENSE +1 -1
- package/README.cn.md +4 -2
- package/README.md +4 -2
- package/docs/README.md +4 -2
- package/docs/classes/event.Event.md +6 -6
- package/docs/classes/event_emitter-1.EventEmitter.md +1 -1
- package/docs/classes/event_emitter.EventEmitter.md +11 -11
- package/docs/modules/all_off.md +1 -1
- package/docs/modules/consts.md +2 -1
- package/docs/modules/default_methods.md +1 -1
- package/docs/modules/has_listeners.md +1 -1
- package/docs/modules/pipe.md +1 -1
- package/docs/modules/pipe_async.md +1 -1
- package/docs/modules/unify.md +1 -1
- package/docs/modules/util_array_remove.md +1 -1
- package/docs/modules/util_object_for_each.md +1 -1
- package/docs/modules/util_string_pad.md +1 -1
- package/docs/modules/util_to_int.md +1 -1
- package/docs/modules/util_valid_callable.md +1 -1
- package/docs/modules/util_valid_object.md +1 -1
- package/docs/modules/wrap_event_emitter.md +2 -2
- package/lib/consts.d.ts +2 -0
- package/lib/consts.js +3 -1
- package/package.json +1 -1
- package/src/consts.js +2 -0
- package/test/add-listeners-test.js +0 -42
- package/test/all-off-test.js +0 -51
- package/test/check-listener-leaks-test.js +0 -76
- package/test/emitter-method-names-test.js +0 -11
- package/test/event-emitter-async-test.js +0 -152
- package/test/event-emitter-test.js +0 -145
- package/test/eventable-test.js +0 -108
- package/test/events-listeners-test.js +0 -46
- package/test/events-remove-listeners-test.js +0 -89
- package/test/has-listeners-test.js +0 -44
- package/test/listeners-side-effects-test.js +0 -40
- package/test/max-listeners-test.js +0 -33
- package/test/modify-in-emit-test.js +0 -121
- package/test/no-error-provided-to-error-event-test.js +0 -38
- package/test/num-args-test.js +0 -41
- package/test/once-test.js +0 -44
- package/test/pipe-async-test.js +0 -58
- package/test/pipe-test.js +0 -57
- package/test/remove-all-listeners-test.js +0 -74
- package/test/set-max-listeners-side-effects-test.js +0 -13
- package/test/subclass-test.js +0 -49
- package/test/unify-async-test.js +0 -122
- package/test/unify-test.js +0 -122
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [commit-and-tag-version](https://github.com/absolute-version/commit-and-tag-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
## [2.0.0-alpha.3](https://github.com/snowyu/events-ex.js/compare/v2.0.0-alpha.2...v2.0.0-alpha.3) (2023-08-27)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* add ABORT state constant ([a8b3710](https://github.com/snowyu/events-ex.js/commit/a8b3710ae7f1695263ed0bd9036db31831ed9ae0))
|
|
11
|
+
|
|
5
12
|
## [2.0.0-alpha.2](https://github.com/snowyu/events-ex.js/compare/v2.0.0-alpha.1...v2.0.0-alpha.2) (2023-06-13)
|
|
6
13
|
|
|
7
14
|
|
package/LICENSE
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Copyright (C)
|
|
1
|
+
Copyright (C) 2015-2023 Riceball LEE (snowyu.lee@gmail.com)
|
|
2
2
|
|
|
3
3
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
4
|
of this software and associated documentation files (the "Software"), to deal
|
package/README.cn.md
CHANGED
|
@@ -87,6 +87,7 @@ my.emit('event');
|
|
|
87
87
|
import {EventEmitter, states} from 'events-ex';
|
|
88
88
|
import {isObject} from 'util-ex';
|
|
89
89
|
|
|
90
|
+
states.ABORT = -1
|
|
90
91
|
class MyDb extends EventEmitter {
|
|
91
92
|
get(key) {
|
|
92
93
|
// Demo the event object bubbling usage:
|
|
@@ -108,8 +109,9 @@ db.on('getting', function(key){
|
|
|
108
109
|
state: states.DONE,
|
|
109
110
|
result: result,
|
|
110
111
|
}
|
|
111
|
-
|
|
112
|
-
|
|
112
|
+
this.stopped = true // it will skip other listeners if true
|
|
113
|
+
} else {
|
|
114
|
+
// you can abort to get key by default.
|
|
113
115
|
this.result = {state: states.ABORT};
|
|
114
116
|
// this.stopped = true // it will skip other listeners if true
|
|
115
117
|
}
|
package/README.md
CHANGED
|
@@ -77,6 +77,7 @@ Bubbling event usage:
|
|
|
77
77
|
import {EventEmitter, states} from 'events-ex';
|
|
78
78
|
import {isObject} from 'util-ex';
|
|
79
79
|
|
|
80
|
+
states.ABORT = -1
|
|
80
81
|
class MyDb extends EventEmitter {
|
|
81
82
|
get(key) {
|
|
82
83
|
// Demo the event object bubbling usage:
|
|
@@ -98,8 +99,9 @@ db.on('getting', function(key){
|
|
|
98
99
|
state: states.DONE,
|
|
99
100
|
result: result,
|
|
100
101
|
}
|
|
101
|
-
|
|
102
|
-
|
|
102
|
+
this.stopped = true // it will skip other listeners if true
|
|
103
|
+
} else {
|
|
104
|
+
// you can abort to get key by default.
|
|
103
105
|
this.result = {state: states.ABORT};
|
|
104
106
|
// this.stopped = true // it will skip other listeners if true
|
|
105
107
|
}
|
package/docs/README.md
CHANGED
|
@@ -77,6 +77,7 @@ Bubbling event usage:
|
|
|
77
77
|
import {EventEmitter, states} from 'events-ex';
|
|
78
78
|
import {isObject} from 'util-ex';
|
|
79
79
|
|
|
80
|
+
states.ABORT = -1
|
|
80
81
|
class MyDb extends EventEmitter {
|
|
81
82
|
get(key) {
|
|
82
83
|
// Demo the event object bubbling usage:
|
|
@@ -98,8 +99,9 @@ db.on('getting', function(key){
|
|
|
98
99
|
state: states.DONE,
|
|
99
100
|
result: result,
|
|
100
101
|
}
|
|
101
|
-
|
|
102
|
-
|
|
102
|
+
this.stopped = true // it will skip other listeners if true
|
|
103
|
+
} else {
|
|
104
|
+
// you can abort to get key by default.
|
|
103
105
|
this.result = {state: states.ABORT};
|
|
104
106
|
// this.stopped = true // it will skip other listeners if true
|
|
105
107
|
}
|
|
@@ -41,7 +41,7 @@ Event Object that contains information about the event, such as the target eleme
|
|
|
41
41
|
|
|
42
42
|
#### Defined in
|
|
43
43
|
|
|
44
|
-
[src/event.js:8](https://github.com/snowyu/events-ex.js/blob/
|
|
44
|
+
[src/event.js:8](https://github.com/snowyu/events-ex.js/blob/2b0a99d/src/event.js#L8)
|
|
45
45
|
|
|
46
46
|
## Properties
|
|
47
47
|
|
|
@@ -53,7 +53,7 @@ Keep your event result here if any.
|
|
|
53
53
|
|
|
54
54
|
#### Defined in
|
|
55
55
|
|
|
56
|
-
[src/event.js:38](https://github.com/snowyu/events-ex.js/blob/
|
|
56
|
+
[src/event.js:38](https://github.com/snowyu/events-ex.js/blob/2b0a99d/src/event.js#L38)
|
|
57
57
|
|
|
58
58
|
___
|
|
59
59
|
|
|
@@ -65,7 +65,7 @@ Whether stop the bubbling event
|
|
|
65
65
|
|
|
66
66
|
#### Defined in
|
|
67
67
|
|
|
68
|
-
[src/event.js:32](https://github.com/snowyu/events-ex.js/blob/
|
|
68
|
+
[src/event.js:32](https://github.com/snowyu/events-ex.js/blob/2b0a99d/src/event.js#L32)
|
|
69
69
|
|
|
70
70
|
___
|
|
71
71
|
|
|
@@ -77,7 +77,7 @@ Who trigger the event
|
|
|
77
77
|
|
|
78
78
|
#### Defined in
|
|
79
79
|
|
|
80
|
-
[src/event.js:26](https://github.com/snowyu/events-ex.js/blob/
|
|
80
|
+
[src/event.js:26](https://github.com/snowyu/events-ex.js/blob/2b0a99d/src/event.js#L26)
|
|
81
81
|
|
|
82
82
|
## Methods
|
|
83
83
|
|
|
@@ -95,7 +95,7 @@ The result of the event.
|
|
|
95
95
|
|
|
96
96
|
#### Defined in
|
|
97
97
|
|
|
98
|
-
[src/event.js:45](https://github.com/snowyu/events-ex.js/blob/
|
|
98
|
+
[src/event.js:45](https://github.com/snowyu/events-ex.js/blob/2b0a99d/src/event.js#L45)
|
|
99
99
|
|
|
100
100
|
___
|
|
101
101
|
|
|
@@ -117,4 +117,4 @@ Initializes the event with the target object.
|
|
|
117
117
|
|
|
118
118
|
#### Defined in
|
|
119
119
|
|
|
120
|
-
[src/event.js:20](https://github.com/snowyu/events-ex.js/blob/
|
|
120
|
+
[src/event.js:20](https://github.com/snowyu/events-ex.js/blob/2b0a99d/src/event.js#L20)
|
|
@@ -22,4 +22,4 @@ Class that represents an event emitter.
|
|
|
22
22
|
|
|
23
23
|
#### Defined in
|
|
24
24
|
|
|
25
|
-
[src/event-emitter.js:7](https://github.com/snowyu/events-ex.js/blob/
|
|
25
|
+
[src/event-emitter.js:7](https://github.com/snowyu/events-ex.js/blob/2b0a99d/src/event-emitter.js#L7)
|
|
@@ -43,7 +43,7 @@ Class that represents an event emitter.
|
|
|
43
43
|
|
|
44
44
|
#### Defined in
|
|
45
45
|
|
|
46
|
-
[src/event-emitter.d.ts:7](https://github.com/snowyu/events-ex.js/blob/
|
|
46
|
+
[src/event-emitter.d.ts:7](https://github.com/snowyu/events-ex.js/blob/2b0a99d/src/event-emitter.d.ts#L7)
|
|
47
47
|
|
|
48
48
|
## Methods
|
|
49
49
|
|
|
@@ -68,7 +68,7 @@ The result of the event.
|
|
|
68
68
|
|
|
69
69
|
#### Defined in
|
|
70
70
|
|
|
71
|
-
[src/event-emitter.d.ts:38](https://github.com/snowyu/events-ex.js/blob/
|
|
71
|
+
[src/event-emitter.d.ts:38](https://github.com/snowyu/events-ex.js/blob/2b0a99d/src/event-emitter.d.ts#L38)
|
|
72
72
|
|
|
73
73
|
___
|
|
74
74
|
|
|
@@ -93,7 +93,7 @@ A promise that resolves with the result of the event.
|
|
|
93
93
|
|
|
94
94
|
#### Defined in
|
|
95
95
|
|
|
96
|
-
[src/event-emitter.d.ts:44](https://github.com/snowyu/events-ex.js/blob/
|
|
96
|
+
[src/event-emitter.d.ts:44](https://github.com/snowyu/events-ex.js/blob/2b0a99d/src/event-emitter.d.ts#L44)
|
|
97
97
|
|
|
98
98
|
___
|
|
99
99
|
|
|
@@ -117,7 +117,7 @@ Returns the count of listeners that are registered to listen for the specified e
|
|
|
117
117
|
|
|
118
118
|
#### Defined in
|
|
119
119
|
|
|
120
|
-
[src/event-emitter.d.ts:66](https://github.com/snowyu/events-ex.js/blob/
|
|
120
|
+
[src/event-emitter.d.ts:66](https://github.com/snowyu/events-ex.js/blob/2b0a99d/src/event-emitter.d.ts#L66)
|
|
121
121
|
|
|
122
122
|
___
|
|
123
123
|
|
|
@@ -141,7 +141,7 @@ Returns an array of functions that are registered to listen for the specified ev
|
|
|
141
141
|
|
|
142
142
|
#### Defined in
|
|
143
143
|
|
|
144
|
-
[src/event-emitter.d.ts:59](https://github.com/snowyu/events-ex.js/blob/
|
|
144
|
+
[src/event-emitter.d.ts:59](https://github.com/snowyu/events-ex.js/blob/2b0a99d/src/event-emitter.d.ts#L59)
|
|
145
145
|
|
|
146
146
|
___
|
|
147
147
|
|
|
@@ -170,7 +170,7 @@ The EventEmitter instance to allow chaining.
|
|
|
170
170
|
|
|
171
171
|
#### Defined in
|
|
172
172
|
|
|
173
|
-
[src/event-emitter.d.ts:32](https://github.com/snowyu/events-ex.js/blob/
|
|
173
|
+
[src/event-emitter.d.ts:32](https://github.com/snowyu/events-ex.js/blob/2b0a99d/src/event-emitter.d.ts#L32)
|
|
174
174
|
|
|
175
175
|
___
|
|
176
176
|
|
|
@@ -199,7 +199,7 @@ The EventEmitter instance to allow chaining.
|
|
|
199
199
|
|
|
200
200
|
#### Defined in
|
|
201
201
|
|
|
202
|
-
[src/event-emitter.d.ts:16](https://github.com/snowyu/events-ex.js/blob/
|
|
202
|
+
[src/event-emitter.d.ts:16](https://github.com/snowyu/events-ex.js/blob/2b0a99d/src/event-emitter.d.ts#L16)
|
|
203
203
|
|
|
204
204
|
___
|
|
205
205
|
|
|
@@ -228,7 +228,7 @@ The EventEmitter instance to allow chaining.
|
|
|
228
228
|
|
|
229
229
|
#### Defined in
|
|
230
230
|
|
|
231
|
-
[src/event-emitter.d.ts:24](https://github.com/snowyu/events-ex.js/blob/
|
|
231
|
+
[src/event-emitter.d.ts:24](https://github.com/snowyu/events-ex.js/blob/2b0a99d/src/event-emitter.d.ts#L24)
|
|
232
232
|
|
|
233
233
|
___
|
|
234
234
|
|
|
@@ -252,7 +252,7 @@ Removes all listeners for a specific event or all events from an event emitter.
|
|
|
252
252
|
|
|
253
253
|
#### Defined in
|
|
254
254
|
|
|
255
|
-
[src/event-emitter.d.ts:51](https://github.com/snowyu/events-ex.js/blob/
|
|
255
|
+
[src/event-emitter.d.ts:51](https://github.com/snowyu/events-ex.js/blob/2b0a99d/src/event-emitter.d.ts#L51)
|
|
256
256
|
|
|
257
257
|
___
|
|
258
258
|
|
|
@@ -272,7 +272,7 @@ ___
|
|
|
272
272
|
|
|
273
273
|
#### Defined in
|
|
274
274
|
|
|
275
|
-
[src/event-emitter.d.ts:52](https://github.com/snowyu/events-ex.js/blob/
|
|
275
|
+
[src/event-emitter.d.ts:52](https://github.com/snowyu/events-ex.js/blob/2b0a99d/src/event-emitter.d.ts#L52)
|
|
276
276
|
|
|
277
277
|
___
|
|
278
278
|
|
|
@@ -293,4 +293,4 @@ ___
|
|
|
293
293
|
|
|
294
294
|
#### Defined in
|
|
295
295
|
|
|
296
|
-
[src/event-emitter.d.ts:67](https://github.com/snowyu/events-ex.js/blob/
|
|
296
|
+
[src/event-emitter.d.ts:67](https://github.com/snowyu/events-ex.js/blob/2b0a99d/src/event-emitter.d.ts#L67)
|
package/docs/modules/all_off.md
CHANGED
|
@@ -41,4 +41,4 @@ Removes all listeners for a specific event or all events from an event emitter.
|
|
|
41
41
|
|
|
42
42
|
#### Defined in
|
|
43
43
|
|
|
44
|
-
[src/all-off.js:12](https://github.com/snowyu/events-ex.js/blob/
|
|
44
|
+
[src/all-off.js:12](https://github.com/snowyu/events-ex.js/blob/2b0a99d/src/all-off.js#L12)
|
package/docs/modules/consts.md
CHANGED
|
@@ -18,10 +18,11 @@
|
|
|
18
18
|
|
|
19
19
|
| Name | Type |
|
|
20
20
|
| :------ | :------ |
|
|
21
|
+
| `ABORT` | `number` |
|
|
21
22
|
| `CONTINUE` | `any` |
|
|
22
23
|
| `DONE` | `number` |
|
|
23
24
|
| `STOPPED` | `number` |
|
|
24
25
|
|
|
25
26
|
#### Defined in
|
|
26
27
|
|
|
27
|
-
[src/consts.js:
|
|
28
|
+
[src/consts.js:6](https://github.com/snowyu/events-ex.js/blob/2b0a99d/src/consts.js#L6)
|
|
@@ -48,4 +48,4 @@ Renames and re-exports [getEventableMethods](default_methods.md#geteventablemeth
|
|
|
48
48
|
|
|
49
49
|
#### Defined in
|
|
50
50
|
|
|
51
|
-
[src/default-methods.js:8](https://github.com/snowyu/events-ex.js/blob/
|
|
51
|
+
[src/default-methods.js:8](https://github.com/snowyu/events-ex.js/blob/2b0a99d/src/default-methods.js#L8)
|
|
@@ -37,4 +37,4 @@ Renames and re-exports [hasListeners](has_listeners.md#haslisteners)
|
|
|
37
37
|
|
|
38
38
|
#### Defined in
|
|
39
39
|
|
|
40
|
-
[src/has-listeners.js:10](https://github.com/snowyu/events-ex.js/blob/
|
|
40
|
+
[src/has-listeners.js:10](https://github.com/snowyu/events-ex.js/blob/2b0a99d/src/has-listeners.js#L10)
|
package/docs/modules/pipe.md
CHANGED
|
@@ -46,4 +46,4 @@ Creates a pipeline between two event emitters, so that any events emitted by the
|
|
|
46
46
|
|
|
47
47
|
#### Defined in
|
|
48
48
|
|
|
49
|
-
[src/pipe.js:21](https://github.com/snowyu/events-ex.js/blob/
|
|
49
|
+
[src/pipe.js:21](https://github.com/snowyu/events-ex.js/blob/2b0a99d/src/pipe.js#L21)
|
|
@@ -46,4 +46,4 @@ Creates a pipeline between two event emitters, so that any events emitted by the
|
|
|
46
46
|
|
|
47
47
|
#### Defined in
|
|
48
48
|
|
|
49
|
-
[src/pipe-async.js:21](https://github.com/snowyu/events-ex.js/blob/
|
|
49
|
+
[src/pipe-async.js:21](https://github.com/snowyu/events-ex.js/blob/2b0a99d/src/pipe-async.js#L21)
|
package/docs/modules/unify.md
CHANGED
|
@@ -43,4 +43,4 @@ Unifies the event listeners of two event emitter objects so that they share the
|
|
|
43
43
|
|
|
44
44
|
#### Defined in
|
|
45
45
|
|
|
46
|
-
[src/unify.js:17](https://github.com/snowyu/events-ex.js/blob/
|
|
46
|
+
[src/unify.js:17](https://github.com/snowyu/events-ex.js/blob/2b0a99d/src/unify.js#L17)
|
|
@@ -36,4 +36,4 @@ Renames and re-exports [remove](util_array_remove.md#remove)
|
|
|
36
36
|
|
|
37
37
|
#### Defined in
|
|
38
38
|
|
|
39
|
-
[src/util/array-remove.js:5](https://github.com/snowyu/events-ex.js/blob/
|
|
39
|
+
[src/util/array-remove.js:5](https://github.com/snowyu/events-ex.js/blob/2b0a99d/src/util/array-remove.js#L5)
|
|
@@ -38,4 +38,4 @@ Renames and re-exports [forEach](util_object_for_each.md#foreach)
|
|
|
38
38
|
|
|
39
39
|
#### Defined in
|
|
40
40
|
|
|
41
|
-
[src/util/object-for-each.js:6](https://github.com/snowyu/events-ex.js/blob/
|
|
41
|
+
[src/util/object-for-each.js:6](https://github.com/snowyu/events-ex.js/blob/2b0a99d/src/util/object-for-each.js#L6)
|
|
@@ -37,4 +37,4 @@ Renames and re-exports [pad](util_string_pad.md#pad)
|
|
|
37
37
|
|
|
38
38
|
#### Defined in
|
|
39
39
|
|
|
40
|
-
[src/util/string-pad.js:8](https://github.com/snowyu/events-ex.js/blob/
|
|
40
|
+
[src/util/string-pad.js:8](https://github.com/snowyu/events-ex.js/blob/2b0a99d/src/util/string-pad.js#L8)
|
|
@@ -36,4 +36,4 @@ Renames and re-exports [toInt](util_to_int.md#toint)
|
|
|
36
36
|
|
|
37
37
|
#### Defined in
|
|
38
38
|
|
|
39
|
-
[src/util/to-int.js:2](https://github.com/snowyu/events-ex.js/blob/
|
|
39
|
+
[src/util/to-int.js:2](https://github.com/snowyu/events-ex.js/blob/2b0a99d/src/util/to-int.js#L2)
|
|
@@ -36,4 +36,4 @@ Renames and re-exports [validCallable](util_valid_callable.md#validcallable)
|
|
|
36
36
|
|
|
37
37
|
#### Defined in
|
|
38
38
|
|
|
39
|
-
[src/util/valid-callable.js:1](https://github.com/snowyu/events-ex.js/blob/
|
|
39
|
+
[src/util/valid-callable.js:1](https://github.com/snowyu/events-ex.js/blob/2b0a99d/src/util/valid-callable.js#L1)
|
|
@@ -36,4 +36,4 @@ Renames and re-exports [validObject](util_valid_object.md#validobject)
|
|
|
36
36
|
|
|
37
37
|
#### Defined in
|
|
38
38
|
|
|
39
|
-
[src/util/valid-object.js:3](https://github.com/snowyu/events-ex.js/blob/
|
|
39
|
+
[src/util/valid-object.js:3](https://github.com/snowyu/events-ex.js/blob/2b0a99d/src/util/valid-object.js#L3)
|
|
@@ -30,7 +30,7 @@ Renames and re-exports [wrapEventEmitter](wrap_event_emitter.md#wrapeventemitter
|
|
|
30
30
|
|
|
31
31
|
#### Defined in
|
|
32
32
|
|
|
33
|
-
[src/wrap-event-emitter.js:6](https://github.com/snowyu/events-ex.js/blob/
|
|
33
|
+
[src/wrap-event-emitter.js:6](https://github.com/snowyu/events-ex.js/blob/2b0a99d/src/wrap-event-emitter.js#L6)
|
|
34
34
|
|
|
35
35
|
## Functions
|
|
36
36
|
|
|
@@ -54,4 +54,4 @@ o or new Event instance
|
|
|
54
54
|
|
|
55
55
|
#### Defined in
|
|
56
56
|
|
|
57
|
-
[src/wrap-event-emitter.js:33](https://github.com/snowyu/events-ex.js/blob/
|
|
57
|
+
[src/wrap-event-emitter.js:33](https://github.com/snowyu/events-ex.js/blob/2b0a99d/src/wrap-event-emitter.js#L33)
|
package/lib/consts.d.ts
CHANGED
package/lib/consts.js
CHANGED
package/package.json
CHANGED
package/src/consts.js
CHANGED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import {assert} from "chai";
|
|
2
|
-
import {EventEmitter} from '../src'
|
|
3
|
-
|
|
4
|
-
describe('EventEmitter', () => {
|
|
5
|
-
it('should add listeners', () => {
|
|
6
|
-
var e = new EventEmitter();
|
|
7
|
-
|
|
8
|
-
var events_new_listener_emited = [];
|
|
9
|
-
var listeners_new_listener_emited = [];
|
|
10
|
-
var times_hello_emited = 0;
|
|
11
|
-
|
|
12
|
-
// sanity check
|
|
13
|
-
assert.equal(e.addListener, e.on);
|
|
14
|
-
|
|
15
|
-
e.on('newListener', function(event, listener) {
|
|
16
|
-
events_new_listener_emited.push(event);
|
|
17
|
-
listeners_new_listener_emited.push(listener);
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
function hello(a, b) {
|
|
21
|
-
times_hello_emited += 1;
|
|
22
|
-
assert.equal('a', a);
|
|
23
|
-
assert.equal('b', b);
|
|
24
|
-
}
|
|
25
|
-
e.on('hello', hello);
|
|
26
|
-
|
|
27
|
-
var foo = function foo() {};
|
|
28
|
-
e.once('foo', foo);
|
|
29
|
-
|
|
30
|
-
e.emit('hello', 'a', 'b');
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
// just make sure that this doesn't throw:
|
|
34
|
-
var f = new EventEmitter();
|
|
35
|
-
f.setMaxListeners(0);
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
assert.deepEqual(['hello', 'foo'], events_new_listener_emited);
|
|
39
|
-
assert.deepEqual([hello, foo], listeners_new_listener_emited);
|
|
40
|
-
assert.equal(1, times_hello_emited);
|
|
41
|
-
});
|
|
42
|
-
});
|
package/test/all-off-test.js
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import {assert} from "chai";
|
|
2
|
-
|
|
3
|
-
import ee from '../src/wrap-event-emitter'
|
|
4
|
-
import allOff from '../src/all-off'
|
|
5
|
-
|
|
6
|
-
describe('all-off', () => {
|
|
7
|
-
it('should remove all listeners', () => {
|
|
8
|
-
var x, count, count2;
|
|
9
|
-
|
|
10
|
-
x = ee();
|
|
11
|
-
count = 0;
|
|
12
|
-
count2 = 0;
|
|
13
|
-
x.on('foo', function () {
|
|
14
|
-
++count;
|
|
15
|
-
});
|
|
16
|
-
x.on('foo', function () {
|
|
17
|
-
++count;
|
|
18
|
-
});
|
|
19
|
-
x.on('bar', function () {
|
|
20
|
-
++count2;
|
|
21
|
-
});
|
|
22
|
-
x.on('bar', function () {
|
|
23
|
-
++count2;
|
|
24
|
-
});
|
|
25
|
-
allOff(x, 'foo');
|
|
26
|
-
x.emit('foo');
|
|
27
|
-
x.emit('bar');
|
|
28
|
-
assert.equal(count, 0, "foo off: type");
|
|
29
|
-
assert.equal(count2, 2, "foo off: ohter type");
|
|
30
|
-
|
|
31
|
-
count = 0;
|
|
32
|
-
count2 = 0;
|
|
33
|
-
x.on('foo', function () {
|
|
34
|
-
++count;
|
|
35
|
-
});
|
|
36
|
-
x.on('foo', function () {
|
|
37
|
-
++count;
|
|
38
|
-
});
|
|
39
|
-
x.on('bar', function () {
|
|
40
|
-
++count2;
|
|
41
|
-
});
|
|
42
|
-
x.on('bar', function () {
|
|
43
|
-
++count2;
|
|
44
|
-
});
|
|
45
|
-
allOff(x);
|
|
46
|
-
x.emit('foo');
|
|
47
|
-
x.emit('bar');
|
|
48
|
-
assert.equal(count, 0, "All off: type");
|
|
49
|
-
assert.equal(count2, 0, "All off: other type");
|
|
50
|
-
});
|
|
51
|
-
});
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import {assert} from "chai";
|
|
2
|
-
import {EventEmitter} from '../src'
|
|
3
|
-
|
|
4
|
-
describe('EventEmitter', () => {
|
|
5
|
-
it('should check listener leaks', () => {
|
|
6
|
-
var oldError = console.error;
|
|
7
|
-
var oldTrace = console.trace;
|
|
8
|
-
console.error = function(){};
|
|
9
|
-
console.trace = function(){};
|
|
10
|
-
|
|
11
|
-
var e = new EventEmitter();
|
|
12
|
-
|
|
13
|
-
// default
|
|
14
|
-
for (var i = 0; i < 10; i++) {
|
|
15
|
-
e.on('default', function() {});
|
|
16
|
-
}
|
|
17
|
-
assert.ok(!e._events['default'].hasOwnProperty('warned'));
|
|
18
|
-
e.on('default', function() {});
|
|
19
|
-
assert.ok(e._events['default'].warned, 'should warned on default event');
|
|
20
|
-
|
|
21
|
-
// specific
|
|
22
|
-
e.setMaxListeners(5);
|
|
23
|
-
for (var i = 0; i < 5; i++) {
|
|
24
|
-
e.on('specific', function() {});
|
|
25
|
-
}
|
|
26
|
-
assert.ok(!e._events['specific'].hasOwnProperty('warned'));
|
|
27
|
-
e.on('specific', function() {});
|
|
28
|
-
assert.ok(e._events['specific'].warned, 'should warned on specific event');
|
|
29
|
-
|
|
30
|
-
// only one
|
|
31
|
-
e.setMaxListeners(1);
|
|
32
|
-
e.on('only one', function() {});
|
|
33
|
-
assert.ok(!e._events['only one'].hasOwnProperty('warned'));
|
|
34
|
-
e.on('only one', function() {});
|
|
35
|
-
assert.ok(e._events['only one'].hasOwnProperty('warned'), 'should warned on only one event');
|
|
36
|
-
|
|
37
|
-
// unlimited
|
|
38
|
-
e.setMaxListeners(0);
|
|
39
|
-
for (var i = 0; i < 1000; i++) {
|
|
40
|
-
e.on('unlimited', function() {});
|
|
41
|
-
}
|
|
42
|
-
assert.ok(!e._events['unlimited'].hasOwnProperty('warned'), 'should not warned on unlimited');
|
|
43
|
-
|
|
44
|
-
// process-wide
|
|
45
|
-
EventEmitter.defaultMaxListeners = 42;
|
|
46
|
-
e = new EventEmitter();
|
|
47
|
-
|
|
48
|
-
for (var i = 0; i < 42; ++i) {
|
|
49
|
-
e.on('fortytwo', function() {});
|
|
50
|
-
}
|
|
51
|
-
assert.ok(!e._events['fortytwo'].hasOwnProperty('warned'));
|
|
52
|
-
e.on('fortytwo', function() {});
|
|
53
|
-
assert.ok(e._events['fortytwo'].hasOwnProperty('warned'));
|
|
54
|
-
delete e._events['fortytwo'].warned;
|
|
55
|
-
|
|
56
|
-
EventEmitter.defaultMaxListeners = 44;
|
|
57
|
-
e.on('fortytwo', function() {});
|
|
58
|
-
assert.ok(!e._events['fortytwo'].hasOwnProperty('warned'));
|
|
59
|
-
e.on('fortytwo', function() {});
|
|
60
|
-
assert.ok(e._events['fortytwo'].hasOwnProperty('warned'));
|
|
61
|
-
|
|
62
|
-
// but _maxListeners still has precedence over defaultMaxListeners
|
|
63
|
-
EventEmitter.defaultMaxListeners = 42;
|
|
64
|
-
e = new EventEmitter();
|
|
65
|
-
e.setMaxListeners(1);
|
|
66
|
-
e.on('uno', function() {});
|
|
67
|
-
assert.ok(!e._events['uno'].hasOwnProperty('warned'));
|
|
68
|
-
e.on('uno', function() {});
|
|
69
|
-
assert.ok(e._events['uno'].hasOwnProperty('warned'), 'should warned on uno event');
|
|
70
|
-
|
|
71
|
-
// chainable
|
|
72
|
-
assert.strictEqual(e, e.setMaxListeners(1), 'setMaxListeners chainable');
|
|
73
|
-
console.error = oldError;
|
|
74
|
-
console.trace = oldTrace;
|
|
75
|
-
});
|
|
76
|
-
});
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import {assert} from "chai";
|
|
2
|
-
import {EventEmitter} from '../src'
|
|
3
|
-
|
|
4
|
-
describe('EventEmitter', () => {
|
|
5
|
-
it('should test method names', () => {
|
|
6
|
-
var E = EventEmitter.prototype;
|
|
7
|
-
assert.equal(E.constructor.name, 'EventEmitter');
|
|
8
|
-
assert.equal(E.on, E.addListener); // Same method.
|
|
9
|
-
assert.equal(E.off, E.removeListener); // Same method.
|
|
10
|
-
});
|
|
11
|
-
})
|