Lightweight, strongly-typed events, with monitored subscriptions.
npm install sub-eventssh
npm i sub-events
`
Usage
* On event-provider side:
`ts
import {SubEvent} from 'sub-events';
// creating a strongly-typed event:
const e: SubEvent = new SubEvent();
// triggering the event when needed:
e.emit('hello');
`
API: [SubEvent], [emit]
* On event-consumer side:
`ts
// subscribing to the event:
const sub = e.subscribe((data: string) => {
// data = 'hello'
});
// cancel the subscription when no longer needed:
sub.cancel();
`
API: [Subscription], [subscribe], [cancel]
$3
Class [SubEventCount] extends [SubEvent] with event [onCount], to observe the number of subscriptions:
`ts
import {SubEventCount, ISubCountChange} from 'sub-events';
// creating a strongly-typed event:
const e: SubEventCount = new SubEventCount();
e.onCount.subscribe((info: ISubCountChange) => {
// number of subscriptions has changed;
// info = {newCount, prevCount}
});
// any subscription will trigger event onCount:
const sub = e.subscribe(data => {});
// cancelling a subscription will trigger onCount:
sub.cancel();
`
API: [SubEventCount], [onCount]
$3
When including directly from HTML, you can access all types under subEvents namespace:
`html
``