Use Facebook's dispatcher

This commit is contained in:
Aldo Cortesi 2015-01-01 16:59:58 +13:00
parent b09dbbe209
commit 4506bafddc
3 changed files with 349 additions and 63 deletions

File diff suppressed because one or more lines are too long

View File

@ -6,7 +6,8 @@
"lodash": "",
"react": "",
"react-router": "",
"bootstrap": ""
"bootstrap": "",
"flux": ""
},
"devDependencies": {
"bower": "",

View File

@ -1,30 +1,13 @@
var flux = require("flux");
const PayloadSources = {
VIEW: "view",
SERVER: "server"
};
function Dispatcher() {
this.callbacks = [];
}
Dispatcher.prototype.register = function (callback) {
this.callbacks.push(callback);
};
Dispatcher.prototype.unregister = function (callback) {
var index = this.callbacks.indexOf(callback);
if (index >= 0) {
this.callbacks.splice(index, 1);
}
};
Dispatcher.prototype.dispatch = function (payload) {
console.debug("dispatch", payload);
for (var i = 0; i < this.callbacks.length; i++) {
this.callbacks[i](payload);
}
};
AppDispatcher = new Dispatcher();
AppDispatcher = new flux.Dispatcher();
AppDispatcher.dispatchViewAction = function (action) {
action.source = PayloadSources.VIEW;
this.dispatch(action);