aboutsummaryrefslogtreecommitdiffstats
path: root/web/src/js/dispatcher.js
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2014-09-16 16:26:16 +1200
committerAldo Cortesi <aldo@nullcube.com>2014-09-16 16:27:09 +1200
commit6efe1aa6a92ce7f9f264903e9d27fb5cf6c32bfe (patch)
treee654b27eeb7a44c61c0e1a43850966735aefb3cd /web/src/js/dispatcher.js
parent6bac1540bd9383c4e6e0510d9b75db34346187ed (diff)
downloadmitmproxy-6efe1aa6a92ce7f9f264903e9d27fb5cf6c32bfe.tar.gz
mitmproxy-6efe1aa6a92ce7f9f264903e9d27fb5cf6c32bfe.tar.bz2
mitmproxy-6efe1aa6a92ce7f9f264903e9d27fb5cf6c32bfe.zip
We're not ready for ES6
Lets re-evaluate in June next year when it's actually released
Diffstat (limited to 'web/src/js/dispatcher.js')
-rw-r--r--web/src/js/dispatcher.js35
1 files changed, 35 insertions, 0 deletions
diff --git a/web/src/js/dispatcher.js b/web/src/js/dispatcher.js
new file mode 100644
index 00000000..310f9a7f
--- /dev/null
+++ b/web/src/js/dispatcher.js
@@ -0,0 +1,35 @@
+const PayloadSources = {
+ VIEW_ACTION: "VIEW_ACTION",
+ SERVER_ACTION: "SERVER_ACTION"
+};
+
+
+ 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);
+ }
+ };
+ Dispatcher.prototype.dispatch=function(payload) {"use strict";
+ console.debug("dispatch", payload);
+ this.callbacks.forEach(function(callback) {
+ callback(payload);
+ });
+ };
+
+
+AppDispatcher = new Dispatcher();
+AppDispatcher.dispatchViewAction = function(action) {
+ action.actionSource = PayloadSources.VIEW_ACTION;
+ this.dispatch(action);
+};
+AppDispatcher.dispatchServerAction = function(action) {
+ action.actionSource = PayloadSources.SERVER_ACTION;
+ this.dispatch(action);
+};