@mohayonao/dispatcher

simple dispatcher

Stats

stars 🌟issues ⚠️updated 🛠created 🐣size 🏋️‍♀️
10Jul 17, 2015Jul 6, 2015Minified + gzip package size for @mohayonao/dispatcher in KB

Readme

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

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.