Options
All
  • Public
  • Public/Protected
  • All
Menu

Class EventDispatcher

Event dispatcher class which implements event exchange functionality.

author

Jānis Radiņš / Kristaps Peļņa

Hierarchy

Index

Accessors

listenerCount

  • get listenerCount(): number

Methods

addEventListener

  • Add event listener.

    Parameters

    • event: string

      Event name for which to listen to

    • listener: EventListener

      Listener function that will be invoked as event with specified name is dispatched.

    • Optional scope: Object

      Listener scope which will be applied as listener is invoked. (You can leave it undefined, if you don't care about scope that much).

    Returns EventMapping

    Null in case if event name is already mapped to same function. Or EventMapping object which is to be used in order to set some of mapping properties like once() which will make listener to be executed upon first event dispatch and then be gone.

Private dispatchEvent

  • dispatchEvent(event: Event): boolean
  • dispatchEvent(eventType: string, eventData?: any): boolean
  • Dispatch event object to all subscribed listeners.

    Parameters

    • event: Event

      Event object that defines event type and data

    Returns boolean

    True if any event mappings to event name have been found; false otherwise.

  • Dispatch event notification by separate type and data arguments.

    Parameters

    • eventType: string

      Event type to be dispatched.

    • Optional eventData: any

      Arbitrary data to ship along with event dispatch.

    Returns boolean

    True if any event mappings to event name have been found; false otherwise.

Protected dispatchEventImpl

  • dispatchEventImpl(event: Event): boolean

hasEventListener

  • hasEventListener(event: string, listener?: EventListener, scope?: Object): boolean
  • Check if event dispatcher has mapping of certain event to listener.

    Parameters

    • event: string

      Target event name.

    • Optional listener: EventListener

      Listener function.

    • Optional scope: Object

      Listener scope which will be applied as listener is invoked.

    Returns boolean

    true if event mapping is found and false otherwise

listenOnce

  • Add event listener that will be executed only once.

    Parameters

    • event: string

      Event name for which to listen to

    • listener: EventListener

      Listener function that will be invoked as event with specified name is dispatched.

    • Optional scope: Object

      Listener scope which will be applied as listener is invoked. (You can leave it undefined, if you don't care about scope that much).

    Returns EventMapping

    Null in case if event name is already mapped to same function. Or EventMapping object which is to be used in order to set some of mapping properties like once() which will make listener to be executed upon first event dispatch and then be gone.

removeAllEventListeners

  • removeAllEventListeners(scope?: Object): boolean
  • Remove all listeners registered with specified scope or with the whole dispatcher instance.

    Parameters

    • Optional scope: Object

      Scope from which all listeners mapped listeners will be removed. If not specified, all listeners will be removed from whole dispatcher instance.

    Returns boolean

    True if any listeners to remove where found; false otherwise.

removeEventListener

  • removeEventListener(event: string, listener: EventListener, scope?: Object): boolean
  • Remove event listener.

    Parameters

    • event: string

      Target event name.

    • listener: EventListener

      Listener function.

    • Optional scope: Object

      Listener scope which will be applied as listener is invoked.

    Returns boolean

    True if event name binding to listener function was found or false if it was found not.

removeEventListeners

  • removeEventListeners(eventType: string, scope?: Object): boolean
  • Remove all listeners of a particular event from all scopes or the specified scope.

    Parameters

    • eventType: string

      Event name to be unmapped from all listeners.

    • Optional scope: Object

      Listener scope from which all listeners mapped to eventType will be removed.

    Returns boolean

    True if any of mappings have been found; false otherwise.