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