Typed event emitter that works both for Web and React Native.

Type Param

interface TypedEventEmitter<T> {
    addListener<K>(type, listener): this;
    emit<K>(type, params): boolean;
    getMaxListeners(): number;
    listenerCount<K>(type): number;
    removeListener<K>(type, listener): this;
    setMaxListeners(n): this;
}

Type Parameters

Methods

  • Adds the specified listener function to the end of the listeners array for the event of the given type.

    Type Parameters

    • K extends string

    Parameters

    • type: K

      A case-sensitive string representing the event type to listen for.

    • listener: EventReceiver<T[K]>

      The callback function.

    Returns this

    A reference to the EventEmitter.

  • Synchronously calls each of the listeners registered for the given event type, in the order they were registered, passing the supplied arguments.

    Type Parameters

    • K extends string

    Parameters

    • type: K

      A case-sensitive string representing the event type.

    • params: T[K]

      Optional parameters.

    Returns boolean

    Whether the event had listeners.

  • Removes the specified listener function from the listener array for the event of the given type.

    Type Parameters

    • K extends string

    Parameters

    • type: K

      A case-sensitive string representing the event type.

    • listener: EventReceiver<T[K]>

      The callback function to unregister.

    Returns this

    A reference to the EventEmitter.

  • By default EventEmitters will print a warning if more than 10 listeners are added for a particular event. Use this function to modify the default threshold.

    Parameters

    • n: number

      Number of listeners before printing a warning. The value can be set toInfinity (or 0) to indicate an unlimited number of listeners.

    Returns this

    A reference to the EventEmitter.

Generated using TypeDoc