Mediator
Mediator (pub/sub) implemented on top of accu-router.
Getting started
npm install accu-mediator --save
.instance, new, .create()
Instantiate the mediator:
var Mediator = ;var mediator = ; //or use the default instancevar mediator = instance; //orvar mediator = ;
.subscribe( topic, callback[, receiver] );
Subscribe to topics
//topics are route paths, see accu-router for route examplesmediator; //add a receiver context for your callbackmediator;
The callback will be invoked in the context of the receiver with arguments
of [topic, ...arg]
. This is how your callback knows which event triggered
it when a token or wildcard was used to register it.
.publish( topic[, ...arg] )
Publish topics. Data arguments are optional.
mediator;
The publish method returns false
if no callbacks were registered or a Promise
for the resolution of all callbacks. The Promise
will resolve to an array of
all callback values.
mediator;
.unsubscribe( topic, callback[, receiver] );
Remove all callbacks subscribed with the same parameters.
mediator;mediator;