Comparing version 0.1.0 to 0.1.1
@@ -8,11 +8,18 @@ var _ = require('lodash'); | ||
var dirtyStores = []; | ||
var dispatching = false; | ||
function dispatch(type, payload) { | ||
if (dispatching) { | ||
return Promise.reject('Cascading dispatches are prohibited. Fix your flux.'); | ||
} | ||
dispatching = true; | ||
return new Promise(function (resolve, reject) { | ||
logger.logMessage(type, payload); | ||
bus.push({type: type, payload: payload}); | ||
logger.logDirtyStores(dirtyStores); | ||
pushChanges(dirtyStores); | ||
clearDirtyMarks(); | ||
resolve(); | ||
try { | ||
logger.logMessage(type, payload); | ||
bus.push({type: type, payload: payload}); | ||
pushChanges(); | ||
resolve(); | ||
} finally { | ||
dispatching = false; | ||
} | ||
}); | ||
@@ -34,14 +41,15 @@ } | ||
function pushChanges(dirtyStores) { | ||
setTimeout(function () { | ||
_.each(dirtyStores, function (store) { | ||
store.changes.push(store.output); | ||
}); | ||
}, 0); | ||
function pushChanges() { | ||
var also = false; | ||
while(dirtyStores.length > 0) { | ||
logger.logDirtyStores(dirtyStores, also); | ||
var stores = dirtyStores; | ||
dirtyStores = []; | ||
_.each(stores, function (store) { | ||
store.changes.push(store.output); | ||
}); | ||
also = true; | ||
} | ||
} | ||
function clearDirtyMarks() { | ||
dirtyStores = []; | ||
} | ||
module.exports = { | ||
@@ -48,0 +56,0 @@ dispatch: dispatch, |
@@ -39,6 +39,6 @@ var _ = require('lodash'); | ||
logDirtyStores: function (dirtyStores) { | ||
logDirtyStores: function (dirtyStores, also) { | ||
if (!debug.enabled) { return; } | ||
if (dirtyStores.length) { | ||
console.log("CHANGED STORES: %s", _.pluck(dirtyStores, 'displayName').join(', ')); | ||
console.log("%sCHANGED STORES: %s", (also ? 'ALSO ' : ''), _.pluck(dirtyStores, 'displayName').join(', ')); | ||
} else { | ||
@@ -45,0 +45,0 @@ console.log("NO STORES CHANGED."); |
{ | ||
"name": "harukaze", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "A reactive flux architecture implementation", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
6233
165