Skip to content

Commit

Permalink
Merge pull request #74 from tommoor/master
Browse files Browse the repository at this point in the history
Allow any number of arguments to be passed to Dispatcher.dispatch
  • Loading branch information
darcyadams committed Mar 23, 2015
2 parents 02e8ea3 + 273a77c commit 1de551e
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/delorean.js
Expand Up @@ -110,10 +110,12 @@
}

// `dispatch` method dispatch the event with `data` (or **payload**)
Dispatcher.prototype.dispatch = function (actionName, data) {
var self = this, stores, deferred;

this.listener.emit('dispatch', actionName, data);
Dispatcher.prototype.dispatch = function () {
var self = this, stores, deferred, args;
args = Array.prototype.slice.call(arguments);

this.listener.emit.apply(this.listener, ['dispatch'].concat(args));

/* Stores are key-value pairs. Collect store instances into an array. */
stores = (function () {
var stores = [], store;
Expand All @@ -130,11 +132,11 @@

// Store instances should wait for finish. So you can know if all the
// stores are dispatched properly.
deferred = this.waitFor(stores, actionName);
deferred = this.waitFor(stores, args[0]);

/* Payload should send to all related stores. */
for (var storeName in self.stores) {
self.stores[storeName].dispatchAction(actionName, data);
self.stores[storeName].dispatchAction.apply(self.stores[storeName], args);
}

// `dispatch` returns deferred object you can just use **promise**
Expand Down

0 comments on commit 1de551e

Please sign in to comment.