Package Exports
- barracks
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (barracks) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Barracks
An event dispatcher for the flux architecture. Best used with browserify.
Installation
$ npm i --save barracksOverview
/**
* Initialize a dispatcher.
*/
var barracks = require('barracks');
var dispatcher = barracks({
users: {
add: function(usr) {console.log(usr + ' got added')},
remove: function() {}
},
courses: {
get: function() {},
put: function() {}
}
});
/**
* Dispatch an event.
*/
dispatcher.dispatch('users_add', 'Loki');
// => 'Loki got added'API
barracks()
Initialize a new barracks instance with an {Object} actions as an argument.
The actions object should contain functions, namespaced at most one level
deep.
// Initialize without namespaces.
var dispatcher = barracks({
user: function() {},
group: function() {}
});
// Initialize with namespaces.
var dispatcher = barracks({
users: {
add: function() {},
remove: function() {}
},
courses: {
get: function() {},
put: function() {}
}
});.dispatch()
dispatcher.dispatch() takes an argument of {String} action and optional
{Any} data. By dispatching an action you call the corresponding function from
the dispatcher and pass it the data. You can think of it as just calling a
function.
In order to access namespaced functions you can delimit your string with
underscores. So to access courses.get you'd dispatch the string courses_get.
Keep in mind that since you can only namespace 1 level deep, your dispatched actions should have no more than one underscore in them.
// Call a non-namespaced action.
dispatcher.dispatch('group', [123, 'hello']);
// Call a namespaced action.
dispatcher.dispatch('users_add', {foo: 'bar'});