ClassEventConsumer<T, E>

Encapsulates an event object, in order to hide its methods SubEvent.emit and SubEvent.cancelAll, so the event consumer can only receive the event, but cannot emit it, or cancel other subscriptions.

It is a non-extendable class, with the same signature as SubEvent, minus emit and cancelAll.

// Example of using EventConsumer inside a component.

import {SubEvent, EventConsumer} from 'sub-events';

class MyComponent {

private event: SubEvent<string> = new SubEvent(); // internal, send-receive event

readonly safeEvent: EventConsumer<string>; // public, receive-only event container

constructor() {
this.safeEvent = new EventConsumer(this.event);

// or even simpler:
// this.safeEvent = this.event.toConsumer();

// clients can only receive data from such "safeEvent",
// they cannot emit data or cancel other subscriptions.
}
}

Type Parameters

Constructors

Accessors

Methods

Constructors

Accessors

Methods

  • Forwards into SubEvent.toPromise of the contained event.

    Parameters

    • Optionaloptions: {
          name?: string;
          timeout?: number;
      }
      • Optionalname?: string
      • Optionaltimeout?: number

    Returns Promise<T>