Comparing version 0.0.1 to 0.0.2
26
index.js
@@ -6,15 +6,15 @@ (function() { | ||
function Dispatcher() { | ||
this._stores = {}; | ||
this._registered = {}; | ||
// format: {actionA: [storeA, storeB], actionB: [storeC]} | ||
this._actionHandlers = {}; | ||
} | ||
Dispatcher.prototype = { | ||
get registered() { | ||
return this._registered; | ||
get actionHandlers() { | ||
return this._actionHandlers; | ||
}, | ||
register: function(action, store) { | ||
if (this.registeredFor(action).indexOf(store) !== -1) return; | ||
if (this.registered.hasOwnProperty(action)) { | ||
this.registered[action].push(store); | ||
if (this.actionHandlers.hasOwnProperty(action)) { | ||
this.actionHandlers[action].push(store); | ||
} else { | ||
this.registered[action] = [store]; | ||
this.actionHandlers[action] = [store]; | ||
} | ||
@@ -24,3 +24,3 @@ }, | ||
var actionArgs = [].slice.call(arguments, 1); | ||
(this._registered[action] || []).forEach(function(store) { | ||
(this.actionHandlers[action] || []).forEach(function(store) { | ||
if (typeof store[action] === "function") { | ||
@@ -32,3 +32,3 @@ store[action].apply(store, actionArgs); | ||
registeredFor: function(action) { | ||
return this.registered[action] || []; | ||
return this.actionHandlers[action] || []; | ||
} | ||
@@ -42,13 +42,13 @@ }; | ||
DocBrown.createActions = function(dispatcher, actions) { | ||
DocBrown.createActions = function(dispatcher, actionNames) { | ||
if (!(dispatcher instanceof Dispatcher)) { | ||
throw new Error("Invalid dispatcher"); | ||
} | ||
if (!Array.isArray(actions)) { | ||
if (!Array.isArray(actionNames)) { | ||
throw new Error("Invalid actions array"); | ||
} | ||
var baseActions = actions.reduce(function(actions, name) { | ||
var baseActions = actionNames.reduce(function(actions, name) { | ||
actions[name] = dispatcher.dispatch.bind(dispatcher, name); | ||
return actions; | ||
}, {_dispatcher: dispatcher, _registered: actions}); | ||
}, {_dispatcher: dispatcher, _registered: actionNames}); | ||
baseActions.only = function() { | ||
@@ -55,0 +55,0 @@ if (!arguments.length) return this; |
{ | ||
"name": "docbrown", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "Flux experiment.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
24527