A utility class for objects that emit events and allow listeners to be registered on them.

EventedSupport can be used in a prototype chain of a class to wire in the event notification system. For example, you can create a custom implementation of Store interface in order to be able to emit store specific events.

Implements

Constructors

Methods

Constructors

  • Constructs the utility that allows to emit events and register event handlers.

    Parameters

    • Optional supportedEvents: string[]

      event names that the are expected to be emitted

    • Optional strictMode: boolean

      if 'true' any attempt to register a handler that is not on the supportedEvents list will throw an error.

    Returns EventedSupport

Methods

  • Emits an event. Calling this method will cause all registered callbacks for the given event type to be invoked. Any additional parameters that are passed to this function will be passed as arguments to the callback functions.

    Parameters

    • event: string

      the event type to emit

    • Rest ...args: any[]

      additional parameters that describe the emitted event

    Returns void

  • Registers a callback function for a given event type.

    Parameters

    • event: string

      the event type to register on

    • callback: ((...args) => void)

      the callback function to register

        • (...args): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    • Optional context: any

      the context in which the callback function should be invoked implementation dependent.

    Returns Handle

    a handle to the registered callback with a single function 'remove'. This function can be used to unregister the callback function.

  • Registers a callback function on the specified target object for a given event type.

    Parameters

    • target: Evented

      the target object

    • event: string

      the event type to register on

    • callback: (() => void)

      the callback function to register

        • (): void
        • Returns void

    • Optional context: any

      the context in which the callback function should be invoked implementation dependent.

    Returns Handle

    a handle to the registered callback with a single function 'remove'. This function can be used to unregister the callback function.

  • Registers a callback function on the specified target object for a given event type. This function behaves identical to 'on' with the exception that the registered callback function will be automatically removed when it has been triggered one time.

    Parameters

    • target: Evented

      the target object

    • event: string

      the event type to register on

    • callback: (() => void)

      the callback function to register

        • (): void
        • Returns void

    • Optional context: any

      the context in which the callback function should be invoked implementation dependent.

    Returns Handle

    a handle to the registered callback with a single function 'remove'. This function can be used to unregister the callback function.