subscribers

    1.0.2 • Public • Published

    subscribers

    A tiny library to manage lists of subscribers. Think of it as a “single event”. Use it when an event emitter is too much.

    Focus has been minimal API surface and fast notification.

    Installation

    npm install subscribers
    

    API

    1. Import the library:
    var subscribers = require('subscribers');
    1. create a list of subscribers
    var list = subscribers();
    // or in ES6:
    const {subscribe, notify} = subscribers();
    1. register subscribers:
    list.subscribe(function() { /* ... */ });
    subscribe(() => {}); // ES6
    1. notify subscribers:
    list.notify({some: 'value'} /*, ... */);
    notify({any: 'other value'} /*, ... */); // does not depend on `this` binding
    1. unsubscribe:
    var unsubscribe = subscribe(function() {});
    unsubscribe();
    1. Use it in other objects:
    class UnicornNews {
      constructor() {
        const {notify, subscribe} = subscribers();
        this.subscribe = subscribe; // does not depend on `this` binding
      }
    }

    Install

    npm i subscribers

    DownloadsWeekly Downloads

    3

    Version

    1.0.2

    License

    ISC

    Last publish

    Collaborators

    • davidaurelio