RetainEmitter
Event emitter that retains event data when notified.
After a notification happens, subsequent calls to add will get automatically notified.
You can use another emitter in order to cancel the last retained event:
You can reset the state of the emitter, i.e., making it forget about the last event using:
1import {Emitter, RetainedEmitter} from '@wonderlandengine/api';
2
3const onStart = new RetainedEmitter();
4onStart.notify(42);
5onStart.add((data) => console.log(data)) // Prints '42'.
6
7// Reset the state of the emitter.
8onStart.reset();
9onStart.add((data) => console.log(data)) // Doesn't print anything.
For more information about emitters, please have a look at the base Emitter class.
- RetainEmitter
- .data
- .isDataRetained
- .add(listener, opts) ⇒ RetainEmitter<T>
- .notify(…data) ⇒ void
- .notifyUnsafe(…data) ⇒ void
- .once(listener, immediate) ⇒ RetainEmitter<T>
- .reset() ⇒ RetainEmitter<T>
.data: undefined | T
Returns the retained data, or undefined if no data was retained.
.isDataRetained: boolean
true if data is retained from the last event, false otherwise.
.add(listener: ListenerCallback<T>, opts: Partial<RetainListenerOptions>) ⇒ RetainEmitter<T>
| Param | Type | Description |
|---|---|---|
| listener | ListenerCallback<T> | |
| opts | Partial<RetainListenerOptions> |
.notify(…data: T[]) ⇒ void
| Param | Type | Description |
|---|---|---|
| data | T |
.notifyUnsafe(…data: T[]) ⇒ void
| Param | Type | Description |
|---|---|---|
| data | T |
.once(listener: ListenerCallback<T>, immediate: boolean) ⇒ RetainEmitter<T>
Returns: Reference to self (for method chaining).
| Param | Type | Description |
|---|---|---|
| listener | ListenerCallback<T> | The callback to register. |
| immediate | boolean | If true, directly resolves if the emitter retains a value. |
.reset() ⇒ RetainEmitter<T>
Reset the state of the emitter.
Further call to add will not automatically resolve, until a new call to notify is performed.
Returns: Reference to self (for method chaining)