0.1.0 • Published 10 years ago

envoi v0.1.0

Weekly downloads
-
License
-
Repository
-
Last release
10 years ago

Mediator

Loosely coupled pub sub accross modules

Installation

$ npm install Diplomat

Usage

var mediator = new Mediator()

mediator.subscribe( "chat", logChatEvent )
mediator.subscribe( "chat::message", displayMessage )

// 'chat' and 'chat::message' will fire because of namespacing
mediator.publish( "chat::message", "shaggy87", "lol dope" )

Api

Mediator.prototype.subscribe( channel, callback, context )

Subscribe to the given channel/namespace. Call the given callback with the given context as 'this' when that channels is published to.

Mediator.prototype.unsubscribe( channel, callback )

Unsubscribe from channel. If only channel is given all callbacks that match the channels namspace will be removed. If callback is given it will only remove subscriptions that has that specific callback

Mediator.prototype.publish( channel, args.. )

Publishes to the channel, calling all subscribing callbacks with the rest of the arguments as arguments to the calback functions.

License

MIT licensed

0.1.0

10 years ago

0.0.21

11 years ago

0.0.2

11 years ago

0.0.11

11 years ago