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:

1import {Emitter, RetainedEmitter} from '@wonderlandengine/api';
2
3const onStart = new RetainedEmitter();
4
5onStart.notify(42);
6onStart.add((data) => console.log(data)) // Prints '42'.

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.

.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, opts: Partial<RetainListenerOptions>) ⇒ RetainEmitter 

ParamTypeDescription
listenerListenerCallback
optsPartial<RetainListenerOptions>

.notify(…data: T[]) ⇒ void 

ParamTypeDescription
dataT

.notifyUnsafe(…data: T[]) ⇒ void 

ParamTypeDescription
dataT

.once(listener: ListenerCallback, immediate: boolean) ⇒ RetainEmitter 

Returns: Reference to self (for method chaining).

ParamTypeDescription
listenerListenerCallbackThe callback to register.
immediatebooleanIf true, directly resolves if the emitter retains a value.

.reset() ⇒ RetainEmitter 

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)