sub-events
TypeScript icon, indicating that this package has built-in type declarations

1.10.1 • Public • Published

Strongly-Typed Events

Build Status

Lightweight, strongly-typed events, with monitored subscriptions.

  • Documentation: API + WiKi.
  • Compatible with all existing events - see Extras.

Install

npm i sub-events

Usage

  • On event-provider side:
import {SubEvent} from 'sub-events';

// creating a strongly-typed event: 
const e: SubEvent<string> = new SubEvent();

// triggering the event when needed:
e.emit('hello');

API: SubEvent, emit

  • On event-consumer side:
// 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

Monitoring Subscriptions

Class SubEventCount extends SubEvent with event onCount, to observe the number of subscriptions:

import {SubEventCount, ISubCountChange} from 'sub-events';

// creating a strongly-typed event:
const e: SubEventCount<string> = 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

Browser

When including directly from HTML, you can access all types under subEvents namespace:

<script src="./node_modules/sub-events/dist"></script>
<script>
    const e = new subEvents.SubEvent();
    e.subscribe(data => {
        // data received
    });
</script>

Note that pre-built script includes only the core library, without the Extras, which you can bundle yourself as needed.

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.10.1220latest
2.0.0-beta.11beta

Version History

VersionDownloads (Last 7 Days)Published
1.10.1220
1.10.060
2.0.0-beta.11
1.9.11
1.9.0160
1.8.96
1.8.81
1.8.71
1.8.627
1.8.52,849
1.9.0-beta.51
1.9.0-beta.41
1.9.0-beta.31
1.9.0-beta.21
1.9.0-beta.11
1.9.0-beta.01
1.8.41
1.8.31
1.8.21
1.8.11
1.8.01
1.7.41
1.7.31
1.7.21
1.7.11
1.7.01
1.6.11
1.6.01
1.5.41
1.5.31
1.5.21
1.5.11
1.5.01
1.5.0-beta.01
1.4.01
1.3.61
1.3.51
1.3.41
1.3.31
1.3.21
1.3.11
1.3.01
1.2.01
1.1.31
1.1.21
1.1.11
1.1.01
1.1.0-Beta.01
1.0.61
1.0.51
1.0.41
1.0.31
1.0.21
1.0.11
1.0.01
0.10.11
0.10.01
0.9.01
0.8.41
0.8.31
0.8.21
0.8.11
0.8.01
0.7.31
0.7.21
0.7.11
0.7.01
0.6.01
0.5.51
0.5.41
0.5.31
0.5.21
0.5.11
0.5.01
0.4.01
0.3.01
0.2.11
0.2.01
0.1.11
0.1.01
0.0.91
0.0.81
0.0.71
0.0.61
0.0.51
0.0.41
0.0.31
0.0.21
0.0.11

Package Sidebar

Install

npm i sub-events

Weekly Downloads

3,405

Version

1.10.1

License

MIT

Unpacked Size

111 kB

Total Files

28

Last publish

Collaborators

  • vitaly.tomilov