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:

import {Emitter, RetainedEmitter} from '@wonderlandengine/api';

const onStart = new RetainedEmitter();

onStart.notify(42);
onStart.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:

import {Emitter, RetainedEmitter} from '@wonderlandengine/api';

const onStart = new RetainedEmitter();
onStart.notify(42);
onStart.add((data) => console.log(data)) // Prints '42'.

// Reset the state of the emitter.
onStart.reset();
onStart.add((data) => console.log(data)) // Doesn't print anything.

For more information about emitters, please have a look at the base Emitter class.

Properties

Methods


Properties

.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.



Methods

.add(listener: ListenerCallback<T>, opts: Partial<RetainListenerOptions>) ⇒ RetainEmitter<T>

ParamTypeDescription
listenerListenerCallback<T>
optsPartial<RetainListenerOptions>

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

ParamTypeDescription
dataT

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

ParamTypeDescription
dataT

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

Returns: Reference to self (for method chaining).

ParamTypeDescription
listenerListenerCallback<T>The callback to register.
immediatebooleanIf 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)