Barracks
![Coverage Status](https://coveralls.io/repos/yoshuawuyts/barracks/badge.png?branch=master)
An event dispatcher for the flux architecture. Best used with browserify.
Installation
npm i --save barracks
Overview
var Dispatcher = require('barracks');
var dispatcher = Dispatcher();
dispatcher.register('eventName', function(arg) {
return arg + ' got triggered';
});
dispatcher.dispatch('eventName', 'Loki');
API
.register()
Register a new object to the store. Takes a {String} action
that determines the
message it should respond to, and a {Function} callback
that executes the response.
dispatcher.register('eventName', function(arg) {
return arg;
});
dispatcher.register('otherEvent', function() {
return 'hi';
)});
.dispatch()
Trigger all callbacks corresponding to {String} action
and provide them an
argument of {Mixed} data
.
dispatcher.dispatch('eventName', 12);
dispatcher.dispatch('otherEvent');
dispatcher.dispatch('otherEvent', null);
License
MIT © Yoshua Wuyts