/* @flow weak */
var __callbacks = [];

/**
 * @memberof Marbles
 * @mixin
 * @desc Simple FLUX Dispatcher
 */
var Dispatcher = {
	/**
	 * @method
	 * @param {function} callback Function to call events with
	 * @returns {Number} Dispatch index
	 */
	register: function (callback) {
		__callbacks.push(callback);
		var dispatchIndex = __callbacks.length - 1;
		return dispatchIndex;
	},

	/**
	 * @method
	 * @param {Object} event An event object
	 * @returns {Promise} Resolves when all registered callbacks have been called
	 */
	dispatch: function (event) {
		var promises = __callbacks.map(function (callback) {
			return new Promise(function (resolve) {
				resolve(callback(event));
			});
		});
		return Promise.all(promises);
	}
};

export default Dispatcher;

@@ -31,16 +31,48 @@
 ks = %5B%5D;
+%0Avar __lock = Promise.resolve();
 %0A%0A/**%0A *
@@ -585,16 +585,54 @@
 vent) %7B%0A
+%09%09__lock = __lock.then(function () %7B%0A%09
 %09%09var pr
@@ -681,16 +681,17 @@
 k) %7B%0A%09%09%09
+%09
 return n
@@ -726,16 +726,17 @@
 ) %7B%0A%09%09%09%09
+%09
 resolve(
@@ -760,20 +760,22 @@
 %0A%09%09%09
+%09
 %7D);%0A
+%09
 %09%09%7D);%0A%09%09
 retu
@@ -766,24 +766,25 @@
 );%0A%09%09%09%7D);%0A%09%09
+%09
 return Promi
@@ -801,16 +801,39 @@
 mises);%0A
+%09%09%7D);%0A%09%09return __lock;%0A
 %09%7D%0A%7D;%0A%0Ae

Fix dispatcher