diff options
author | Jason <jason.daurus@gmail.com> | 2016-06-16 16:46:13 +0800 |
---|---|---|
committer | Jason <jason.daurus@gmail.com> | 2016-06-17 05:08:05 +0800 |
commit | 7fb0836bfedefd851403ba440e88bc04548cf7b0 (patch) | |
tree | aeb2426ce9325c0f55fcaecadfd4e54f1910ed6f /web | |
parent | b88937f1e039e306f95a760ea181fcdcc6fec1fa (diff) | |
download | mitmproxy-7fb0836bfedefd851403ba440e88bc04548cf7b0.tar.gz mitmproxy-7fb0836bfedefd851403ba440e88bc04548cf7b0.tar.bz2 mitmproxy-7fb0836bfedefd851403ba440e88bc04548cf7b0.zip |
[web] remove store
Diffstat (limited to 'web')
-rw-r--r-- | web/src/js/ducks/settings.js | 14 | ||||
-rw-r--r-- | web/src/js/store/store.js | 91 | ||||
-rw-r--r-- | web/src/js/store/view.js | 0 |
3 files changed, 7 insertions, 98 deletions
diff --git a/web/src/js/ducks/settings.js b/web/src/js/ducks/settings.js index 8513c2f1..05499da5 100644 --- a/web/src/js/ducks/settings.js +++ b/web/src/js/ducks/settings.js @@ -60,14 +60,14 @@ export function fetch() { export function handleWsMsg(msg) { return (dispatch, getState) => { - if (msg.cmd === STORE_CMDS_RESET) { - const req = getState().settings.req - if (req) { - req.abort() - } - return dispatch(reset(msg.data)) + if (msg.cmd !== STORE_CMDS_RESET) { + return dispatch({ type: RECV_WS_MSG, cmd: msg.cmd, data: msg.data }) + } + const req = getState().settings.req + if (req) { + req.abort() } - dispatch({ type: RECV_WS_MSG, cmd: msg.cmd, data: msg.data }) + dispatch(reset(msg.data)) } } diff --git a/web/src/js/store/store.js b/web/src/js/store/store.js deleted file mode 100644 index df3a23ab..00000000 --- a/web/src/js/store/store.js +++ /dev/null @@ -1,91 +0,0 @@ - -import _ from "lodash"; -import $ from "jquery"; -import {EventEmitter} from 'events'; -import {ActionTypes, StoreCmds} from "../actions.js"; -import {AppDispatcher} from "../dispatcher.js"; - - -function DictStore() { - EventEmitter.call(this); - this.reset(); -} -_.extend(DictStore.prototype, EventEmitter.prototype, { - update: function (dict) { - _.merge(this.dict, dict); - this.emit("recalculate"); - }, - reset: function (dict) { - this.dict = dict || {}; - this.emit("recalculate"); - } -}); - -function LiveStoreMixin(type) { - this.type = type; - - this._updates_before_fetch = undefined; - this._fetchxhr = false; - - this.handle = this.handle.bind(this); - AppDispatcher.register(this.handle); - - // Avoid double-fetch on startup. - if (!(window.ws && window.ws.readyState === WebSocket.CONNECTING)) { - this.fetch(); - } -} -_.extend(LiveStoreMixin.prototype, { - handle: function (event) { - if (event.type === ActionTypes.CONNECTION_OPEN) { - return this.fetch(); - } - if (event.type === this.type) { - if (event.cmd === StoreCmds.RESET) { - this.fetch(event.data); - } else if (this._updates_before_fetch) { - console.log("defer update", event); - this._updates_before_fetch.push(event); - } else { - this[event.cmd](event.data); - } - } - }, - close: function () { - AppDispatcher.unregister(this.handle); - }, - fetch: function (data) { - console.log("fetch " + this.type); - if (this._fetchxhr) { - this._fetchxhr.abort(); - } - this._updates_before_fetch = []; // (JS: empty array is true) - if (data) { - this.handle_fetch(data); - } else { - this._fetchxhr = $.getJSON("/" + this.type) - .done(function (message) { - this.handle_fetch(message.data); - }.bind(this)) - .fail(function () { - console.error("Could not fetch " + this.type) - }.bind(this)); - } - }, - handle_fetch: function (data) { - this._fetchxhr = false; - console.log(this.type + " fetched.", this._updates_before_fetch); - this.reset(data); - var updates = this._updates_before_fetch; - this._updates_before_fetch = false; - for (var i = 0; i < updates.length; i++) { - this.handle(updates[i]); - } - }, -}); - -function LiveDictStore(type) { - DictStore.call(this); - LiveStoreMixin.call(this, type); -} -_.extend(LiveDictStore.prototype, DictStore.prototype, LiveStoreMixin.prototype); diff --git a/web/src/js/store/view.js b/web/src/js/store/view.js deleted file mode 100644 index e69de29b..00000000 --- a/web/src/js/store/view.js +++ /dev/null |