mitmproxy/web/src/js/dispatcher.js

36 lines
970 B
JavaScript
Raw Normal View History

2014-09-15 16:08:26 +00:00
const PayloadSources = {
2014-09-15 22:56:43 +00:00
VIEW_ACTION: "VIEW_ACTION",
SERVER_ACTION: "SERVER_ACTION"
2014-09-15 16:08:26 +00:00
};
2014-09-16 09:06:30 +00:00
function Dispatcher() {"use strict";
this.callbacks = [];
}
Dispatcher.prototype.register=function(callback) {"use strict";
this.callbacks.push(callback);
};
Dispatcher.prototype.unregister=function(callback) {"use strict";
var index = this.callbacks.indexOf(f);
if (index >= 0) {
this.callbacks.splice(this.callbacks.indexOf(f), 1);
2014-09-15 22:56:43 +00:00
}
2014-09-16 09:06:30 +00:00
};
Dispatcher.prototype.dispatch=function(payload) {"use strict";
console.debug("dispatch", payload);
this.callbacks.forEach(function(callback) {
callback(payload);
});
};
2014-09-15 16:08:26 +00:00
AppDispatcher = new Dispatcher();
2014-09-15 22:56:43 +00:00
AppDispatcher.dispatchViewAction = function(action) {
action.actionSource = PayloadSources.VIEW_ACTION;
this.dispatch(action);
2014-09-15 22:05:06 +00:00
};
2014-09-15 22:56:43 +00:00
AppDispatcher.dispatchServerAction = function(action) {
action.actionSource = PayloadSources.SERVER_ACTION;
this.dispatch(action);
};