Options
All
  • Public
  • Public/Protected
  • All
Menu

Class EventDispatcher

A class that provides a custom event channel.

You may bind a callback to an event with on or remove with off; trigger-ing an event fires all callbacks in succession.

Hierarchy

Index

Properties

Private _events

_events: EventHandlers

Map of all handlers registered with the "on" function.

Private _listenId

_listenId: string

A unique id that identifies this instance.

Private _listeners

_listeners: EventListeners

Map of all objects that are listening to this instance.

Private _listeningTo

_listeningTo: EventListeners

Map of all objects this instance is listening to.

Methods

Private internalOn

listenTo

  • Inversion-of-control versions of on. Tell this object to listen to an event in another object... keeping track of what it's listening to for easier unbinding later.

    Parameters

    Returns this

listenToOnce

off

  • off(): any
  • off(eventMap: EventMap, context?: any): any
  • off(name: string, callback?: EventCallback, context?: any): any
  • Remove one or many callbacks. If context is null, removes all callbacks with that function. If callback is null, removes all callbacks for the event. If name is null, removes all bound callbacks for all events.

    Returns any

  • Parameters

    • eventMap: EventMap
    • Optional context: any

    Returns any

  • Parameters

    • name: string
    • Optional callback: EventCallback
    • Optional context: any

    Returns any

on

  • on(eventMap: EventMap, context?: any): any
  • on(eventMap: EventMap, callback?: EventCallback, context?: any, priority?: number): any
  • on(name: string, callback: EventCallback, context?: any, priority?: number): any

once

  • once(eventMap: EventMap, context?: any): any
  • once(name: string, callback: EventCallback, context?: any, priority?: any): any
  • Bind an event to only be triggered a single time. After the first time the callback is invoked, its listener will be removed. If multiple events are passed in using the space-separated syntax, the handler will fire once for each event, not once for a combination of all events.

    Parameters

    • eventMap: EventMap
    • Optional context: any

    Returns any

  • Parameters

    • name: string
    • callback: EventCallback
    • Optional context: any
    • Optional priority: any

    Returns any

stopListening

trigger

  • Trigger one or many events, firing all bound callbacks. Callbacks are passed the same arguments as trigger is, apart from the event name (unless you're listening on "all", which will cause your callback to receive the true name of the event as the first argument).

    Parameters

    Returns this

Generated using TypeDoc