mitmproxy/web/src/js/dispatcher.js

36 lines
1.0 KiB
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
};
function Dispatcher() {"use strict";
2014-09-15 22:56:43 +00:00
this.callbacks = [];
}
Dispatcher.prototype.register=function(callback) {"use strict";
2014-09-15 22:56:43 +00:00
this.callbacks.push(callback);
};
Dispatcher.prototype.unregister=function(callback) {"use strict";
2014-09-15 22:56:43 +00:00
var index = this.callbacks.indexOf(f);
if (index >= 0) {
this.callbacks.splice(this.callbacks.indexOf(f), 1);
}
};
Dispatcher.prototype.dispatch=function(payload) {"use strict";
2014-09-15 22:56:43 +00:00
console.debug("dispatch", payload);
this.callbacks.forEach(function(callback) {
2014-09-15 22:56:43 +00:00
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);
};