Class EventEmitter

Object that can emit events for others to listen for. This is used instead of Closure's event system because it is much more light weight. The API is based on Node's EventEmitters.

Hierarchy

Index

Constructor methods

Methods

Constructor methods

constructor(): EventEmitter

constructor

Returns

EventEmitter

Methods

public addListener(type: string, listenerFn: any, opt_scope?: any): EventEmitter

Registers a listener.

Parameters

  • type: string

    The type of event to listen for.

  • listenerFn: any

    The function to invoke when the event is fired.

  • opt_scope?: any optional

    The object in whose scope to invoke the listener.

Returns

EventEmitter

A self reference.

public emit(type: string, var_args?: Array<any>)

Fires an event and calls all listeners.

Parameters

  • type: string

    The type of event to emit.

  • var_args?: Array<any> optional

    Any arguments to pass to each listener.

public listeners(type: string): Array<{ fn: any; oneshot: boolean; scope: any; }>

Returns a mutable list of listeners for a specific type of event.

Parameters

  • type: string

    The type of event to retrieve the listeners for.

Returns

Array<{ fn: any; oneshot: boolean; scope: any; }>

{!Array.<{fn: !Function, oneshot: boolean, scope: (Object|undefined)}>} The registered listeners for the given event type.

public on(type: string, listenerFn: any, opt_scope?: any): EventEmitter

An alias for {@code #addListener()}.

Parameters

  • type: string

    The type of event to listen for.

  • listenerFn: any

    The function to invoke when the event is fired.

  • opt_scope?: any optional

    The object in whose scope to invoke the listener.

Returns

EventEmitter

A self reference.

public once(type: string, listenerFn: any, opt_scope?: any): EventEmitter

Registers a one-time listener which will be called only the first time an event is emitted, after which it will be removed.

Parameters

  • type: string

    The type of event to listen for.

  • listenerFn: any

    The function to invoke when the event is fired.

  • opt_scope?: any optional

    The object in whose scope to invoke the listener.

Returns

EventEmitter

A self reference.

public removeAllListeners(opt_type?: string): EventEmitter

Removes all listeners for a specific type of event. If no event is specified, all listeners across all types will be removed.

Parameters

  • opt_type?: string optional

    The type of event to remove listeners from.

Returns

EventEmitter

A self reference.

public removeListener(type: string, listenerFn: any): EventEmitter

Removes a previously registered event listener.

Parameters

  • type: string

    The type of event to unregister.

  • listenerFn: any

    The handler function to remove.

Returns

EventEmitter

A self reference.