JSPM

  • Created
  • Published
  • Downloads 148
  • Score
    100M100P100Q85904F
  • License MIT

An event dispatcher for the flux architecture

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

NPM version build status Test coverage

An event dispatcher for the flux architecture. Best used with browserify.

Installation

npm i --save barracks

Overview

/**
 * Initialize barracks.
 */

var Dispatcher = require('barracks');
var dispatcher = Dispatcher();

/**
 * Register a new callback.
 */

dispatcher.register('eventName', function(arg) {
  return arg + ' got triggered';
});

/**
 * Dispatch registered callbacks for 'eventName'.
 */

dispatcher.dispatch('eventName', 'Loki');
// => 'Loki got triggered'

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);
// => 12

dispatcher.dispatch('otherEvent');
// => throw Error

dispatcher.dispatch('otherEvent', null);
// => 'hi'

License

MIT © Yoshua Wuyts