Interface IEventDispatcher<T>

A simple event dispatcher interface with IEvent as event type.

interface IEventDispatcher<T> {
    addEventListener(type: T, listener: (event: IEvent<T>) => void): void;
    dispatchEvent(event: IEvent<T>): void;
    hasEventListener(type: T, listener: (event: IEvent<T>) => void): boolean;
    removeEventListener(type: T, listener: (event: IEvent<T>) => void): void;
}

Type Parameters

  • T

Implemented by

Methods

  • Adds a listener to an event type.

    Parameters

    • type: T

      The type of event to listen to.

    • listener: (event: IEvent<T>) => void

      The function that gets called when the event is fired.

    Returns void

  • Fire an event type.

    Parameters

    • event: IEvent<T>

      A simple event interface with typed event types.

      • [attachment: string]: any
      • Optionaltarget?: any
      • type: T

    Returns void

  • Checks if listener is added to an event type.

    Parameters

    • type: T

      The type of event to listen to.

    • listener: (event: IEvent<T>) => void

      The function that gets called when the event is fired.

    Returns boolean

  • Removes a listener from an event type.

    Parameters

    • type: T

      The type of the listener that gets removed.

    • listener: (event: IEvent<T>) => void

      The listener function that gets removed.

    Returns void