diff options
author | Maximilian Hils <git@maximilianhils.com> | 2014-09-15 18:08:26 +0200 |
---|---|---|
committer | Maximilian Hils <git@maximilianhils.com> | 2014-09-15 18:08:26 +0200 |
commit | cbf18320cdbd05197f232da69b3c9a5391735156 (patch) | |
tree | 63b9cf8fd6a8e8fb5be6b2d5a655acf3d33b6229 /web/src/js/Dispatcher.es6.js | |
parent | 9f8d2eea64d4611c1e2f7e7043fe6d3ef9a6aa40 (diff) | |
download | mitmproxy-cbf18320cdbd05197f232da69b3c9a5391735156.tar.gz mitmproxy-cbf18320cdbd05197f232da69b3c9a5391735156.tar.bz2 mitmproxy-cbf18320cdbd05197f232da69b3c9a5391735156.zip |
client-side structure
Diffstat (limited to 'web/src/js/Dispatcher.es6.js')
-rw-r--r-- | web/src/js/Dispatcher.es6.js | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/web/src/js/Dispatcher.es6.js b/web/src/js/Dispatcher.es6.js new file mode 100644 index 00000000..9bf70878 --- /dev/null +++ b/web/src/js/Dispatcher.es6.js @@ -0,0 +1,36 @@ +const PayloadSources = { + VIEW_ACTION: "VIEW_ACTION", + SERVER_ACTION: "SERVER_ACTION" +}; + +class Dispatcher { + + constructor() { + this.callbacks = []; + } + + register(callback){ + this.callbacks.push(callback); + } + + unregister(callback){ + var index = this.callbacks.indexOf(f); + if (index >= 0) { + this.callbacks.splice(this.callbacks.indexOf(f), 1); + } + } + + dispatch(payload){ + console.debug("dispatch", payload); + this.callbacks.forEach((callback) => { + callback(payload); + }); + } + +} + +AppDispatcher = new Dispatcher(); +AppDispatcher.dispatchViewAction = function(action){ + action.actionSource = PayloadSources.VIEW_ACTION; + this.dispatch(action); +};
\ No newline at end of file |