Like an EventEmitter, instances of this class allow us register and unregister listeners for events, but it allows listening for those messages that match a pattern.

Example

let x = new Emitter();
x.addContentListener({foo: 'bar'}, (data) => {
console.log('received data', data);
});
x.emit({foo: 'bar', hello: 'world'})

> received data {foo: 'bar', hello: 'world'}

Hierarchy

Constructors

  • Parameters

    • Optional options: ConstructorOptions

    Returns Emitter

Properties

contentListeners: Listener[] = []

Methods

  • Add an event listener that will be called when an event that matches provided filter is received

    Parameters

    • filter: {
          cancel?: string;
          payload?: any;
          request?: string;
      }

      filter that should match emited events to call provided function

      • Optional cancel?: string
      • Optional payload?: any
      • Optional request?: string
    • fn: ((...args: string[]) => void)

      callback to invoke on each new match.

        • (...args: string[]): void
        • Parameters

          • Rest ...args: string[]

          Returns void

    Returns void

  • Check if given data matches provided filter.

    Returns

    true if item matches filter.

    Parameters

    • item: string

      tested element.

    • filter: {
          cancel?: string;
          payload?: any;
          request?: string;
      }

      tested filter.

      • Optional cancel?: string
      • Optional payload?: any
      • Optional request?: string

    Returns boolean

  • Stop receiving events on a previously added listener.

    Parameters

    • fn: ((...args: string[]) => void)

      callback to remove from listeners list.

        • (...args: string[]): void
        • Parameters

          • Rest ...args: string[]

          Returns void

    Returns void

Generated using TypeDoc