@mohayonao/dispatcher

    0.3.1 • Public • Published

    DISPATCHER

    Build Status NPM Version License

    simple dispatcher

    Installation

    Node.js

    npm install @mohayonao/dispatcher

    API

    Dispatcher

    • constructor()

    Instance methods

    • register(address: string, subscription: function): void
    • register(subscription: function): void
    • register({ delegate: function }): void
    • unregister(address: string, subscription: function): void
    • unregister(subscription: function): void
    • unregister({ delegate: function }): void
    • dispatch(address: string, data: any): void

    Dispatcher.Delegator

    • constructor()

    Instance methods

    • delegate(address: string, data: any): void

    Dispatcher.Duplex

    • constructor()

    Messaging Protocol

    +--------+                  +-------------+
    | source | <-- register --- | destination |
    |        | --- dispatch --> |             |
    +--------+                  +-------------+
    
    interface souce {
      register(address: string, subscription: function): void;
      register(subscription: function): void;
      register({ delegate: function }): void;
      dispatch(address: string, data: any): void;
    }
    
    interface destination {
      delegate(address: string, data: any): void;
    }
    

    address: string must start with "/".

    let publisher = new Dispatcher();
    let subscriber = new Dispatcher.Delegator();
     
    // define action of address
    subscriber["/message/view"] = (message) => {
      console.log(`received: ${message}`);
    };
     
    publisher.register(subscriber);
     
    publisher.dispatch("/message/view", "hello!");
    // -> call subscriber.delegate("/message/view", "hello!")
    // => "received: hello!"

    License

    MIT

    Keywords

    none

    Install

    npm i @mohayonao/dispatcher

    DownloadsWeekly Downloads

    2

    Version

    0.3.1

    License

    MIT

    Last publish

    Collaborators

    • mohayonao