NuGet Package Manager

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

    4.0.1 • Public • Published

    newsletter

    npm install newsletter
    

    Simple pub/sub implementation.

    ESM Package

    Starting from v4.0 this package fully moved to ES Modules and ES2015 code. This means no more build step before publishing to NPM.

    Ideally you shouldn't spot any difference, but in case you face any issues, see this useful article.

    You can also downgrade to v3.x to use all the same functionality, precompiled to ES5.

    API

    To create publisher instance use Newsletter constructor (see Usage). Instance implements next interface:

    • publish - invokes all listeners and pass some received data to them
    • subscribe - adds new listener (function) and returns subscription handling instance

    Usage

    // get newsletter
    import { Newsletter } from 'newsletter';
    
    // create instance
    var signal = new Newsletter();
    
    // subscribe notifications
    var subscription = signal.subscribe((data) => console.log(data));
    
    // publish some data to subscribers
    signal.publish(13);
    
    // remove listener
    subscription.dispose();

    There is a way to subscribe to a single update

    var signal = new Newsletter();
    
    // subscribe to a single update
    var subscription = signal.subscribe((data) => {
      subscription.dispose();
      console.log(data);
    });
    
    // will call a listener and remove it
    signal.publish(13);
    
    // no listeners called
    signal.publish(14);

    The project is licensed under the MIT license.

    Install

    npm i newsletter

    DownloadsWeekly Downloads

    4

    Version

    4.0.1

    License

    MIT

    Unpacked Size

    4.39 kB

    Total Files

    6

    Last publish

    Collaborators

    • alexeyraspopov