Skip to content

Commit 1de551e

Browse files
committed
Merge pull request #74 from tommoor/master
Allow any number of arguments to be passed to Dispatcher.dispatch
2 parents 02e8ea3 + 273a77c commit 1de551e

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/delorean.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,12 @@
110110
}
111111

112112
// `dispatch` method dispatch the event with `data` (or **payload**)
113-
Dispatcher.prototype.dispatch = function (actionName, data) {
114-
var self = this, stores, deferred;
115-
116-
this.listener.emit('dispatch', actionName, data);
113+
Dispatcher.prototype.dispatch = function () {
114+
var self = this, stores, deferred, args;
115+
args = Array.prototype.slice.call(arguments);
116+
117+
this.listener.emit.apply(this.listener, ['dispatch'].concat(args));
118+
117119
/* Stores are key-value pairs. Collect store instances into an array. */
118120
stores = (function () {
119121
var stores = [], store;
@@ -130,11 +132,11 @@
130132

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

135137
/* Payload should send to all related stores. */
136138
for (var storeName in self.stores) {
137-
self.stores[storeName].dispatchAction(actionName, data);
139+
self.stores[storeName].dispatchAction.apply(self.stores[storeName], args);
138140
}
139141

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

0 commit comments

Comments
 (0)