0.3.1 • Published 10 years ago
@mohayonao/dispatcher v0.3.1
DISPATCHER
simple dispatcher
Installation
Node.js
npm install @mohayonao/dispatcherAPI
Dispatcher
constructor()
Instance methods
register(address: string, subscription: function): voidregister(subscription: function): voidregister({ delegate: function }): voidunregister(address: string, subscription: function): voidunregister(subscription: function): voidunregister({ delegate: function }): voiddispatch(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