TinyEmitter¶
Overview¶
Lightweight event & listener abstraction for a single event type.
@author Sam Reid (PhET Interactive Simulations) @author Michael Kauzmann (PhET Interactive Simulations)
Class TinyEmitter¶
Constructor¶
new TinyEmitter( onBeforeNotify? : TinyEmitterOptions<T>['onBeforeNotify'] | null, hasListenerOrderDependencies? : TinyEmitterOptions<T>['hasListenerOrderDependencies'] | null, reentrantNotificationStrategy? : TinyEmitterOptions<T>['reentrantNotificationStrategy'] | null )¶
Instance Methods¶
dispose()¶
Disposes an Emitter. All listeners are removed.
emit( ...args : T )¶
Notify listeners
addListener( listener : TEmitterListener<T> )¶
Adds a listener which will be called during emit.
removeListener( listener : TEmitterListener<T> )¶
Removes a listener
removeAllListeners()¶
Removes all the listeners
hasListener( listener : TEmitterListener<T> ) : boolean¶
Checks whether a listener is registered with this Emitter
hasListeners() : boolean¶
Returns true if there are any listeners.
getListenerCount() : number¶
Returns the number of listeners.
forEachListener( callback : ( listener: TEmitterListener<T> ) => void )¶
Invokes a callback once for each listener - meant for Property's use
Instance Properties¶
changeCount : ( count: number ) => void¶
Not defined usually because of memory usage. If defined, this will be called when the listener count changes, e.g. changeCount( {number} listenersAddedQuantity ), with the number being negative for listeners removed.
isDisposed : boolean¶
Only defined when assertions are enabled - to keep track if it has been disposed or not
Source Code¶
See the source for TinyEmitter.ts in the axon repository.