events-ex 2.1.1 → 2.3.0
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 +20 -0
- package/README.cn.md +119 -170
- package/README.md +140 -150
- package/docs/README.md +143 -149
- package/docs/all-off/README.md +17 -0
- package/docs/all-off/functions/allOff.md +33 -0
- package/docs/consts/README.md +12 -0
- package/docs/consts/variables/RegExpEventSymbol.md +11 -0
- package/docs/consts/variables/states.md +29 -0
- package/docs/default-methods/README.md +17 -0
- package/docs/default-methods/functions/getEventableMethods.md +309 -0
- package/docs/event/README.md +17 -0
- package/docs/event/classes/Event.md +143 -0
- package/docs/event-emitter/README-1.md +17 -0
- package/docs/event-emitter/README.md +17 -0
- package/docs/event-emitter/classes/EventEmitter-1.md +29 -0
- package/docs/event-emitter/classes/EventEmitter.md +369 -0
- package/docs/eventable/README.md +17 -0
- package/docs/eventable/functions/eventable.md +82 -0
- package/docs/has-listeners/README.md +17 -0
- package/docs/has-listeners/functions/hasListeners.md +38 -0
- package/docs/index/README.md +85 -0
- package/docs/modules.md +24 -23
- package/docs/pipe/README.md +17 -0
- package/docs/pipe/functions/pipe.md +41 -0
- package/docs/pipe-async/README.md +17 -0
- package/docs/pipe-async/functions/pipeAsync.md +41 -0
- package/docs/unify/README.md +17 -0
- package/docs/unify/functions/unify.md +35 -0
- package/docs/util/array-remove/README.md +17 -0
- package/docs/util/array-remove/functions/remove.md +21 -0
- package/docs/util/object-for-each/README.md +17 -0
- package/docs/util/object-for-each/functions/forEach.md +29 -0
- package/docs/util/promise-any/README.md +11 -0
- package/docs/util/promise-any/variables/default.md +9 -0
- package/docs/util/string-pad/README.md +17 -0
- package/docs/util/string-pad/functions/pad.md +25 -0
- package/docs/util/to-int/README.md +17 -0
- package/docs/util/to-int/functions/toInt.md +21 -0
- package/docs/util/valid-callable/README.md +17 -0
- package/docs/util/valid-callable/functions/validCallable.md +21 -0
- package/docs/util/valid-object/README.md +17 -0
- package/docs/util/valid-object/functions/validObject.md +21 -0
- package/docs/wrap-event-emitter/README.md +21 -0
- package/docs/wrap-event-emitter/functions/wrapEventEmitter.md +33 -0
- package/docs/wrap-event-emitter/variables/methods.md +11 -0
- package/lib/all-off.d.ts +1 -1
- package/lib/all-off.js +1 -1
- package/lib/default-methods.d.ts +38 -7
- package/lib/default-methods.js +155 -32
- package/lib/event-emitter.d.ts +12 -2
- package/lib/event.d.ts +9 -3
- package/lib/event.js +6 -0
- package/lib/eventable.js +4 -1
- package/lib/pipe-async.d.ts +4 -1
- package/lib/pipe-async.js +39 -5
- package/lib/pipe.d.ts +1 -1
- package/lib/pipe.js +1 -1
- package/lib/unify.d.ts +1 -1
- package/lib/unify.js +1 -1
- package/lib/util/array-remove.js +1 -1
- package/lib/util/object-for-each.js +1 -1
- package/lib/util/promise-any.d.ts +1 -0
- package/lib/util/promise-any.js +44 -0
- package/lib/util/string-pad.js +1 -1
- package/lib/wrap-event-emitter.d.ts +2 -1
- package/lib/wrap-event-emitter.js +24 -3
- package/package.json +17 -17
- package/src/default-methods.js +159 -26
- package/src/event-emitter.d.ts +12 -2
- package/src/event.js +6 -0
- package/src/eventable.js +3 -0
- package/src/pipe-async.js +64 -30
- package/src/util/promise-any.js +45 -0
- package/src/wrap-event-emitter.js +23 -18
- package/docs/.nojekyll +0 -1
- package/docs/classes/event.Event.md +0 -141
- package/docs/classes/event_emitter-1.EventEmitter.md +0 -29
- package/docs/classes/event_emitter.EventEmitter.md +0 -352
- package/docs/modules/all_off.md +0 -44
- package/docs/modules/consts.md +0 -39
- package/docs/modules/default_methods.md +0 -51
- package/docs/modules/event.md +0 -19
- package/docs/modules/event_emitter-1.md +0 -19
- package/docs/modules/event_emitter.md +0 -19
- package/docs/modules/eventable.md +0 -92
- package/docs/modules/has_listeners.md +0 -49
- package/docs/modules/index.md +0 -99
- package/docs/modules/pipe.md +0 -49
- package/docs/modules/pipe_async.md +0 -49
- package/docs/modules/unify.md +0 -46
- package/docs/modules/util_array_remove.md +0 -39
- package/docs/modules/util_object_for_each.md +0 -41
- package/docs/modules/util_string_pad.md +0 -40
- package/docs/modules/util_to_int.md +0 -39
- package/docs/modules/util_valid_callable.md +0 -39
- package/docs/modules/util_valid_object.md +0 -39
- package/docs/modules/wrap_event_emitter.md +0 -57
package/docs/README.md
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
events-ex
|
|
1
|
+
**events-ex**
|
|
2
|
+
|
|
3
|
+
***
|
|
2
4
|
|
|
3
5
|
### events-ex [](https://npmjs.org/package/events-ex) [](https://npmjs.org/package/events-ex) [](https://npmjs.org/package/events-ex)
|
|
4
6
|
|
|
@@ -6,53 +8,60 @@ Browser-friendly enhanced event emitter [ability][Ability] and class. It's modif
|
|
|
6
8
|
|
|
7
9
|
### Features
|
|
8
10
|
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
11
|
+
* **Modular Event-able Ability**: Inject event capabilities into any class using `eventable(MyClass)` without forced inheritance.
|
|
12
|
+
* **Core Event Enhancements**:
|
|
13
|
+
* **Bubbling & Interruption**: Full support for event propagation and mid-stream cancellation.
|
|
14
|
+
* **Listener Ordering**: Precise control via the optional `index` parameter in `on()` and `once()`. Supports special values `'first'` and `'last'` to ensure listeners stay at the boundaries.
|
|
15
|
+
* **Regex Subscription**: Subscribe to multiple events using Regular Expressions.
|
|
16
|
+
* **Hook-able System**: Intercept and modify event behavior at the core level.
|
|
17
|
+
* **Advanced Asynchronous Features (Specific to `emitAsync`)**:
|
|
18
|
+
* **Configurable Concurrency**: Choose between **Serial** (default) and **Parallel** execution for async listeners.
|
|
19
|
+
* **Result Aggregation**: Strategies to gather return values: `last` (default), `first` (first success), and `collect` (all results).
|
|
20
|
+
* **Fluent API Proxies**: Use `.parallel()` and `.configure()` for transient, side-effect-free execution context.
|
|
21
|
+
* **Architecture**: Rewritten core for improved performance and flexibility while maintaining broad compatibility.
|
|
22
|
+
* **Event Utilities**: Built-in support for `pipe`, `pipeAsync`, `unify`, `allOff`, and `hasListeners`.
|
|
15
23
|
|
|
16
24
|
### Differences
|
|
17
25
|
|
|
18
|
-
* Difference with [node events](https://nodejs.org/api/events.html)
|
|
26
|
+
* **Difference with [node events](https://nodejs.org/api/events.html)**
|
|
19
27
|
+ **`broken change`**: The event supports bubbling and interruption
|
|
20
28
|
+ the `event object` as listener's "this" object:
|
|
21
29
|
* `result`: If set, the result is returned to the `Event Emitter`.
|
|
22
30
|
* `stopped`: If set to `true`, it prevents the remaining listeners from being executed.
|
|
23
31
|
* `target`: The `Event Emitter` object, which was originally the `this` object.
|
|
24
32
|
* `type`: triggered event type(name).
|
|
33
|
+
* `resolved`: (Async only) Indicates if a successful result has been found in `first` mode.
|
|
25
34
|
* **`broken change`**: The `emit` return the result of listeners's callback function instead of the successful state.
|
|
26
35
|
* **`broken change`**: The `this` object of listeners' callback function is the `Event` Object instead of the emitter object.
|
|
27
36
|
* The emitter object is put into the `target` property of the `Event` Object.
|
|
28
|
-
*
|
|
29
|
-
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
*
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
37
|
+
* ⚡ **Enhanced `emitAsync` Method (Unique to Async)**:
|
|
38
|
+
* **Sequential (Serial)**: Executes listeners one-by-one, respecting `this.stopped`.
|
|
39
|
+
* **Concurrent (Parallel)**: Executes all listeners simultaneously.
|
|
40
|
+
* **Result Strategies**:
|
|
41
|
+
* `last`: Returns the result of the final listener (or last to finish).
|
|
42
|
+
* `first`: Returns the first successful non-undefined result (skips errors).
|
|
43
|
+
* `collect`: Returns an array of all results in registration order.
|
|
44
|
+
* **Fluent Configuration**: Use `.parallel()` or `.configure({...})` for one-time customized async emits.
|
|
45
|
+
* **Listener APIs**: `on/once(event: string|RegExp, listener, index?: number|'first'|'last')`
|
|
46
|
+
* 📌 **Index Parameter** (Optional): Insertion position in the listener array.
|
|
47
|
+
* `'first'` (`-Infinity`): Stays in the **Head** zone. The first listener added as `'first'` is placed at the very front.
|
|
48
|
+
* `'last'` (`Infinity`): Stays in the **Tail** zone. The first listener added as `'last'` will always remain at the absolute end.
|
|
49
|
+
* `number`: Relative index within the **Body** zone.
|
|
50
|
+
* 🧪 **Regex Event Matching**: Listeners can bind to multiple events via regex patterns.
|
|
51
|
+
|
|
52
|
+
* **Difference with [event-emitter](https://github.com/medikoo/event-emitter)**
|
|
53
|
+
+ **`broken change`**: The event supports bubbling and interruption (see above).
|
|
54
|
+
+ Adds the `defaultMaxListeners` class property to keep compatibility with node events.
|
|
55
|
+
+ Adds the `setMaxListeners` method to keep compatibility with node events.
|
|
43
56
|
+ Adds `error`, `newListener` and `removeListener` events to keep compatibility with node events.
|
|
44
|
-
+ Adds listeners() method to keep compatibility with node events.
|
|
45
|
-
+ Adds listenerCount() class method to keep compatibility with node events.
|
|
57
|
+
+ Adds `listeners()` method to keep compatibility with node events.
|
|
58
|
+
+ Adds `listenerCount()` class method to keep compatibility with node events.
|
|
46
59
|
* Adds async event emitting via `emitAsync` method.
|
|
60
|
+
|
|
47
61
|
* 🔗 **Event Piping & Unification**:
|
|
48
|
-
* `pipe(source, target)`:
|
|
49
|
-
* `
|
|
50
|
-
*
|
|
51
|
-
* Includes `allOff()`, `hasListeners()`, `listenerCount()` for debugging and lifecycle management.
|
|
52
|
-
* Enhances robustness in event-driven architectures.
|
|
53
|
-
* 🔌 **Modular Ability Injection**:
|
|
54
|
-
* `eventable(MyClass)`: Inject event capabilities into any class without inheritance.
|
|
55
|
-
* Configurable inclusion/exclusion of methods to avoid prototype pollution.
|
|
62
|
+
* `pipe(source, target)`: Sync event forwarding.
|
|
63
|
+
* `pipeAsync(source, target, options)`: Async forwarding with configurable concurrency and aggregation.
|
|
64
|
+
* `unify(emitter1, emitter2)`: Bi-directional synchronization.
|
|
56
65
|
|
|
57
66
|
Note: The listener throw error should not broke the notification, but it will emit error(`emit('error', error, 'notify', eventName, listener, args)`) after notification.
|
|
58
67
|
|
|
@@ -64,7 +73,7 @@ npm install events-ex
|
|
|
64
73
|
|
|
65
74
|
### Usage
|
|
66
75
|
|
|
67
|
-
Extends from `EventEmitter` class
|
|
76
|
+
#### Extends from `EventEmitter` class
|
|
68
77
|
|
|
69
78
|
```js
|
|
70
79
|
import {EventEmitter} from 'events-ex';
|
|
@@ -72,7 +81,7 @@ import {EventEmitter} from 'events-ex';
|
|
|
72
81
|
class MyClass extends EventEmitter {}
|
|
73
82
|
```
|
|
74
83
|
|
|
75
|
-
Add/Inject the event-able [ability][Ability] to your class directly
|
|
84
|
+
#### Add/Inject the event-able [ability][Ability] to your class directly
|
|
76
85
|
|
|
77
86
|
```js
|
|
78
87
|
import {eventable} from 'events-ex';
|
|
@@ -83,24 +92,36 @@ class MyClass extends MyRoot {}
|
|
|
83
92
|
eventable(MyClass);
|
|
84
93
|
```
|
|
85
94
|
|
|
86
|
-
|
|
95
|
+
#### Core Feature: Listener Ordering (Index Parameter)
|
|
87
96
|
|
|
88
97
|
```js
|
|
89
|
-
const
|
|
98
|
+
const ee = new EventEmitter();
|
|
99
|
+
ee.on('test', () => console.log('third'));
|
|
100
|
+
ee.on('test', () => console.log('first'), 'first'); // Always at the front
|
|
101
|
+
ee.on('test', () => console.log('last'), 'last'); // Always at the end
|
|
102
|
+
ee.on('test', () => console.log('second'), 1); // Body index 1 (relative to Head)
|
|
103
|
+
|
|
104
|
+
ee.emit('test');
|
|
105
|
+
// Output:
|
|
106
|
+
// first
|
|
107
|
+
// second
|
|
108
|
+
// third
|
|
109
|
+
// last
|
|
110
|
+
```
|
|
90
111
|
|
|
91
|
-
|
|
92
|
-
console.log('event occur');
|
|
93
|
-
});
|
|
112
|
+
#### Core Feature: Regex Subscription
|
|
94
113
|
|
|
95
|
-
|
|
96
|
-
|
|
114
|
+
```js
|
|
115
|
+
const ee = new EventEmitter();
|
|
116
|
+
ee.on(/^user\..*/, function(data) {
|
|
117
|
+
console.log(`Event ${this.type} triggered with`, data);
|
|
97
118
|
});
|
|
98
119
|
|
|
99
|
-
|
|
100
|
-
|
|
120
|
+
ee.emit('user.login', { id: 1 });
|
|
121
|
+
ee.emit('user.logout', { id: 1 });
|
|
101
122
|
```
|
|
102
123
|
|
|
103
|
-
Bubbling
|
|
124
|
+
#### Core Feature: Bubbling & Interruption
|
|
104
125
|
|
|
105
126
|
```js
|
|
106
127
|
import {EventEmitter, states} from 'events-ex';
|
|
@@ -108,7 +129,6 @@ import {isObject} from 'util-ex';
|
|
|
108
129
|
|
|
109
130
|
class MyDb extends EventEmitter {
|
|
110
131
|
get(key) {
|
|
111
|
-
// Demo the event object bubbling usage:
|
|
112
132
|
let result = this.emit('getting', key)
|
|
113
133
|
if(isObject(result)) {
|
|
114
134
|
if (result.state === states.ABORT) return
|
|
@@ -120,149 +140,123 @@ class MyDb extends EventEmitter {
|
|
|
120
140
|
|
|
121
141
|
let db = new MyDb
|
|
122
142
|
db.on('getting', function(key){
|
|
123
|
-
result = myGet(key);
|
|
143
|
+
let result = myGet(key);
|
|
124
144
|
if (result != null) {
|
|
125
|
-
|
|
126
|
-
this.
|
|
127
|
-
state: states.DONE,
|
|
128
|
-
result: result,
|
|
129
|
-
}
|
|
130
|
-
this.stopped = true // it will skip other listeners if true
|
|
145
|
+
this.result = { state: states.DONE, result: result }
|
|
146
|
+
this.stopped = true // Skip remaining listeners
|
|
131
147
|
} else {
|
|
132
|
-
|
|
133
|
-
this.result = {state: states.ABORT};
|
|
134
|
-
// this.stopped = true // it will skip other listeners if true
|
|
148
|
+
this.result = { state: states.ABORT };
|
|
135
149
|
}
|
|
136
150
|
})
|
|
137
151
|
```
|
|
138
152
|
|
|
139
|
-
|
|
153
|
+
#### Async-Only Features: Concurrency & Aggregation
|
|
140
154
|
|
|
141
|
-
|
|
155
|
+
These features apply **only** to the `emitAsync` method.
|
|
142
156
|
|
|
143
|
-
|
|
157
|
+
```js
|
|
158
|
+
const ee = new EventEmitter();
|
|
159
|
+
ee.on('task', async () => {
|
|
160
|
+
await sleep(100);
|
|
161
|
+
return 'result 1';
|
|
162
|
+
});
|
|
163
|
+
ee.on('task', async () => {
|
|
164
|
+
return 'result 2';
|
|
165
|
+
});
|
|
144
166
|
|
|
145
|
-
|
|
146
|
-
ee(
|
|
167
|
+
// 1. Default (Serial): Executes sequentially, returns 'result 2'
|
|
168
|
+
const res = await ee.emitAsync('task');
|
|
147
169
|
|
|
148
|
-
|
|
149
|
-
|
|
170
|
+
// 2. Parallel + Collect: Executes concurrently, returns ['result 1', 'result 2']
|
|
171
|
+
const allResults = await ee.parallel('collect').emitAsync('task');
|
|
150
172
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
173
|
+
// 3. Parallel + First: Executes concurrently, returns fastest success ('result 2')
|
|
174
|
+
const firstResult = await ee.parallel('first').emitAsync('task');
|
|
175
|
+
```
|
|
154
176
|
|
|
155
|
-
|
|
156
|
-
// … react to first 'test' event (invoked only once!)
|
|
157
|
-
});
|
|
177
|
+
### Advanced Features
|
|
158
178
|
|
|
159
|
-
|
|
160
|
-
emitter.emit('test', arg1, arg2/*…args*/); // Only first listener invoked
|
|
179
|
+
#### Async Concurrency Engine (For `emitAsync` Only)
|
|
161
180
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
181
|
+
| Option | Value | Description |
|
|
182
|
+
| :--- | :--- | :--- |
|
|
183
|
+
| **`asyncMode`** | `'serial'` | **(Default)** Listeners run one by one. Supports `this.stopped`. |
|
|
184
|
+
| | `'parallel'` | Listeners run concurrently. `this.stopped` is ignored. |
|
|
185
|
+
| **`resultMode`** | `'last'` | **(Default)** Returns the result of the last listener (or last to finish). |
|
|
186
|
+
| | `'first'` | Returns the first **non-undefined** and **successful** result. Skips errors. |
|
|
187
|
+
| | `'collect'` | Returns an array of all results in registration order. |
|
|
165
188
|
|
|
166
|
-
|
|
189
|
+
#### Proxy Isolation (Fluent API)
|
|
167
190
|
|
|
168
|
-
|
|
191
|
+
Calling `.parallel()` or `.configure()` returns a transient Proxy Object (`Object.create(this)`), allowing thread-safe, isolated configurations for specific emits.
|
|
169
192
|
|
|
170
|
-
|
|
193
|
+
#### Safe Injection (AoP Compatibility) & Name Collisions
|
|
171
194
|
|
|
172
|
-
|
|
173
|
-
* `options` *(object)*: optional options
|
|
174
|
-
* `include` *(string[]|string)*: only these emitter methods will be added to the class
|
|
175
|
-
* **NOTE:** static method should use the prefix '@' with name.
|
|
176
|
-
* `exclude` *(string[]|string)*: theses emitter methods would not be added to the class
|
|
177
|
-
* **NOTE:** static method should use the prefix '@' with name.
|
|
178
|
-
* `methods` *(object)*: hooked methods to the class
|
|
179
|
-
* key: the method name to hook.
|
|
180
|
-
* value: the new method function
|
|
181
|
-
* use `this.super()` to call the original method.
|
|
182
|
-
* `this.self` is the original `this` object.
|
|
183
|
-
* `classMethods` *(object)*: hooked class methods to the class
|
|
195
|
+
When injecting event capabilities into an existing object or prototype via `wrapEventEmitter(target)` or `eventable(MyClass)`, a **minimal set** of methods is injected to minimize the risk of name collisions:
|
|
184
196
|
|
|
185
|
-
|
|
186
|
-
|
|
197
|
+
- `on`, `once`, `off`
|
|
198
|
+
- `emit`, `emitAsync`
|
|
199
|
+
- `setEmitterOptions`
|
|
187
200
|
|
|
188
|
-
|
|
189
|
-
exec() {console.log "my original exec"}
|
|
190
|
-
}
|
|
201
|
+
⚠️ **Warning on Name Collisions**: If your target object already has methods with these names, they will be overwritten.
|
|
191
202
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
+
**Solution: Method Renaming**
|
|
204
|
+
You can use the `rename` option in `eventable` to map the emitter methods to custom names on your target:
|
|
205
|
+
|
|
206
|
+
```js
|
|
207
|
+
eventable(MyClass, {
|
|
208
|
+
rename: {
|
|
209
|
+
emitAsync: 'myEmitAsync',
|
|
210
|
+
on: 'addListener'
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
// Now use: inst.myEmitAsync('event')
|
|
203
214
|
```
|
|
204
215
|
|
|
205
|
-
|
|
216
|
+
**Full EventEmitter vs. Minimal Injection**
|
|
206
217
|
|
|
207
|
-
**
|
|
218
|
+
- **Standalone**: Calling `ee()` or `new EventEmitter()` without a target returns a **full instance** containing all advanced methods (including `.parallel()`, `.configure()`, `.setMaxListeners()`, etc.).
|
|
219
|
+
- **Injected**: Passing a target to `ee(target)` or using `eventable` performs a **minimal injection** to preserve the target's original footprint. Use `setEmitterOptions` on the target to access advanced async configurations.
|
|
208
220
|
|
|
209
|
-
|
|
221
|
+
---
|
|
210
222
|
|
|
211
|
-
|
|
223
|
+
### API
|
|
224
|
+
|
|
225
|
+
#### eventable(class[, options]) _(events-ex/eventable)_
|
|
212
226
|
|
|
213
|
-
|
|
214
|
-
|
|
227
|
+
Add the event-able ability to the class directly.
|
|
228
|
+
|
|
229
|
+
* `class`: the class to be injected the ability.
|
|
230
|
+
* `options` _(object)_: optional options
|
|
231
|
+
* `include` _(string[]|string)_: only these emitter methods will be added to the class
|
|
232
|
+
* `exclude` _(string[]|string)_: theses emitter methods would not be added to the class
|
|
233
|
+
* `methods` _(object)_: hooked methods to the class
|
|
234
|
+
* `emitterOptions` _(object)_: default options for the emitter (e.g., `asyncMode`, `resultMode`).
|
|
235
|
+
* `rename` _(object)_: map the emitter methods to custom names on the class.
|
|
236
|
+
* key: original method name (e.g., 'on', 'emitAsync').
|
|
237
|
+
* value: new method name.
|
|
238
|
+
|
|
239
|
+
#### hasListeners(obj[, name]) _(events-ex/has-listeners)_
|
|
215
240
|
|
|
216
241
|
```javascript
|
|
217
|
-
import {hasListeners, wrapEventEmitter as ee} from 'events-ex
|
|
242
|
+
import {hasListeners, wrapEventEmitter as ee} from 'events-ex';
|
|
218
243
|
var emitter = ee();
|
|
219
244
|
var listener = function () {};
|
|
220
|
-
|
|
221
245
|
hasListeners(emitter); // false
|
|
222
|
-
|
|
223
246
|
emitter.on('foo', listener);
|
|
224
|
-
hasListeners(emitter); // true
|
|
225
247
|
hasListeners(emitter, 'foo'); // true
|
|
226
|
-
hasListeners(emitter, 'bar'); // false
|
|
227
|
-
|
|
228
|
-
emitter.off('foo', listener);
|
|
229
|
-
hasListeners(emitter, 'foo'); // false
|
|
230
248
|
```
|
|
231
249
|
|
|
232
|
-
####
|
|
233
|
-
|
|
234
|
-
Pipes all events from _source_ emitter onto _target_ emitter (all events from _source_ emitter will be emitted also on _target_ emitter, but not other way).
|
|
235
|
-
Returns _pipe_ object which exposes `pipe.close` function. Invoke it to close configured _pipe_.
|
|
236
|
-
It works internally by redefinition of `emit` method, if in your interface this method is referenced differently, provide its name (or symbol) with third argument.
|
|
250
|
+
#### pipeAsync(source, target[, name, options]) _(events-ex/pipe-async)_
|
|
237
251
|
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
Unifies event handling for two objects. Events emitted on _emitter1_ would be also emitter on _emitter2_, and other way back.
|
|
241
|
-
Non reversible.
|
|
242
|
-
|
|
243
|
-
```javascript
|
|
244
|
-
import {unify as eeUnify, wrapEventEmitter as ee} from 'events-ex';
|
|
252
|
+
Creates an asynchronous pipeline.
|
|
245
253
|
|
|
246
|
-
|
|
247
|
-
|
|
254
|
+
- `options.asyncMode`: Propagation mode (`'serial' | 'parallel'`).
|
|
255
|
+
- `options.resultMode`: Aggregation strategy.
|
|
248
256
|
|
|
249
|
-
|
|
250
|
-
emitter2.on('test', listener2 = function () { });
|
|
257
|
+
#### setEmitterOptions(options)
|
|
251
258
|
|
|
252
|
-
|
|
253
|
-
emitter2.emit('test'); // Invoked listener2
|
|
254
|
-
|
|
255
|
-
var unify = eeUnify(emitter1, emitter2);
|
|
256
|
-
|
|
257
|
-
emitter1.emit('test'); // Invoked listener1 and listener2
|
|
258
|
-
emitter2.emit('test'); // Invoked listener1 and listener2
|
|
259
|
-
|
|
260
|
-
emitter1.on('test', listener3 = function () { });
|
|
261
|
-
emitter2.on('test', listener4 = function () { });
|
|
262
|
-
|
|
263
|
-
emitter1.emit('test'); // Invoked listener1, listener2, listener3 and listener4
|
|
264
|
-
emitter2.emit('test'); // Invoked listener1, listener2, listener3 and listener4
|
|
265
|
-
```
|
|
259
|
+
Configures instance-wide defaults for `asyncMode`, `resultMode`, and `maxListeners`.
|
|
266
260
|
|
|
267
261
|
[event-emitter]: https://github.com/medikoo/event-emitter
|
|
268
262
|
[Ability]: https://github.com/snowyu/custom-ability.js
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
[**events-ex**](../../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[events-ex](../../modules.md) / [all-off](../README.md) / allOff
|
|
6
|
+
|
|
7
|
+
# Function: allOff()
|
|
8
|
+
|
|
9
|
+
> **allOff**(`emitter`, `type?`): [`EventEmitter`](../../event-emitter/classes/EventEmitter.md)
|
|
10
|
+
|
|
11
|
+
Defined in: [src/all-off.js:12](https://github.com/snowyu/events-ex.js/blob/53cfb5bb3f7229cb549e99d410c0d6d39665eb0a/src/all-off.js#L12)
|
|
12
|
+
|
|
13
|
+
Removes all listeners for a specific event or all events from an event emitter.
|
|
14
|
+
|
|
15
|
+
## Parameters
|
|
16
|
+
|
|
17
|
+
### emitter
|
|
18
|
+
|
|
19
|
+
[`EventEmitter`](../../event-emitter/classes/EventEmitter.md)
|
|
20
|
+
|
|
21
|
+
The event emitter to remove listeners from.
|
|
22
|
+
|
|
23
|
+
### type?
|
|
24
|
+
|
|
25
|
+
`string`
|
|
26
|
+
|
|
27
|
+
The event to remove listeners for. If not provided, all listeners for all events will be removed.
|
|
28
|
+
|
|
29
|
+
## Returns
|
|
30
|
+
|
|
31
|
+
[`EventEmitter`](../../event-emitter/classes/EventEmitter.md)
|
|
32
|
+
|
|
33
|
+
- The event emitter with all listeners removed.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
[**events-ex**](../../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[events-ex](../../modules.md) / [consts](../README.md) / RegExpEventSymbol
|
|
6
|
+
|
|
7
|
+
# Variable: RegExpEventSymbol
|
|
8
|
+
|
|
9
|
+
> `const` **RegExpEventSymbol**: `symbol` \| `"@@RegExpEvent"`
|
|
10
|
+
|
|
11
|
+
Defined in: [src/consts.js:13](https://github.com/snowyu/events-ex.js/blob/53cfb5bb3f7229cb549e99d410c0d6d39665eb0a/src/consts.js#L13)
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
[**events-ex**](../../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[events-ex](../../modules.md) / [consts](../README.md) / states
|
|
6
|
+
|
|
7
|
+
# Variable: states
|
|
8
|
+
|
|
9
|
+
> `const` **states**: `object`
|
|
10
|
+
|
|
11
|
+
Defined in: [src/consts.js:6](https://github.com/snowyu/events-ex.js/blob/53cfb5bb3f7229cb549e99d410c0d6d39665eb0a/src/consts.js#L6)
|
|
12
|
+
|
|
13
|
+
## Type Declaration
|
|
14
|
+
|
|
15
|
+
### ABORT
|
|
16
|
+
|
|
17
|
+
> **ABORT**: `number`
|
|
18
|
+
|
|
19
|
+
### CONTINUE
|
|
20
|
+
|
|
21
|
+
> **CONTINUE**: `any`
|
|
22
|
+
|
|
23
|
+
### DONE
|
|
24
|
+
|
|
25
|
+
> **DONE**: `number`
|
|
26
|
+
|
|
27
|
+
### STOPPED
|
|
28
|
+
|
|
29
|
+
> **STOPPED**: `number`
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
[**events-ex**](../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[events-ex](../modules.md) / default-methods
|
|
6
|
+
|
|
7
|
+
# default-methods
|
|
8
|
+
|
|
9
|
+
## Functions
|
|
10
|
+
|
|
11
|
+
- [getEventableMethods](functions/getEventableMethods.md)
|
|
12
|
+
|
|
13
|
+
## References
|
|
14
|
+
|
|
15
|
+
### default
|
|
16
|
+
|
|
17
|
+
Renames and re-exports [getEventableMethods](functions/getEventableMethods.md)
|