diff options
author | Maximilian Hils <git@maximilianhils.com> | 2016-06-04 18:53:41 -0700 |
---|---|---|
committer | Maximilian Hils <git@maximilianhils.com> | 2016-06-04 18:53:41 -0700 |
commit | d53a2de0ba69bea6c7aefa87782ad249cfb4ea76 (patch) | |
tree | 25e474bf95e4f83022708e84184d8d7d56a6e3ce /web/src/js/store | |
parent | e880f532ad3c66ebfded4655b7fa67a367a83cc7 (diff) | |
download | mitmproxy-d53a2de0ba69bea6c7aefa87782ad249cfb4ea76.tar.gz mitmproxy-d53a2de0ba69bea6c7aefa87782ad249cfb4ea76.tar.bz2 mitmproxy-d53a2de0ba69bea6c7aefa87782ad249cfb4ea76.zip |
web: completely move flow state to redux
Diffstat (limited to 'web/src/js/store')
-rw-r--r-- | web/src/js/store/store.js | 59 | ||||
-rw-r--r-- | web/src/js/store/view.js | 111 |
2 files changed, 0 insertions, 170 deletions
diff --git a/web/src/js/store/store.js b/web/src/js/store/store.js index 65355684..f3e2074f 100644 --- a/web/src/js/store/store.js +++ b/web/src/js/store/store.js @@ -6,55 +6,6 @@ import {ActionTypes, StoreCmds} from "../actions.js"; import {AppDispatcher} from "../dispatcher.js"; -function ListStore() { - EventEmitter.call(this); - this.reset(); -} -_.extend(ListStore.prototype, EventEmitter.prototype, { - add: function (elem) { - if (elem.id in this._pos_map) { - return; - } - this._pos_map[elem.id] = this.list.length; - this.list.push(elem); - this.emit("add", elem); - }, - update: function (elem) { - if (!(elem.id in this._pos_map)) { - return; - } - this.list[this._pos_map[elem.id]] = elem; - this.emit("update", elem); - }, - remove: function (elem_id) { - if (!(elem_id in this._pos_map)) { - return; - } - this.list.splice(this._pos_map[elem_id], 1); - this._build_map(); - this.emit("remove", elem_id); - }, - reset: function (elems) { - this.list = elems || []; - this._build_map(); - this.emit("recalculate"); - }, - _build_map: function () { - this._pos_map = {}; - for (var i = 0; i < this.list.length; i++) { - var elem = this.list[i]; - this._pos_map[elem.id] = i; - } - }, - get: function (elem_id) { - return this.list[this._pos_map[elem_id]]; - }, - index: function (elem_id) { - return this._pos_map[elem_id]; - } -}); - - function DictStore() { EventEmitter.call(this); this.reset(); @@ -133,12 +84,6 @@ _.extend(LiveStoreMixin.prototype, { }, }); -function LiveListStore(type) { - ListStore.call(this); - LiveStoreMixin.call(this, type); -} -_.extend(LiveListStore.prototype, ListStore.prototype, LiveStoreMixin.prototype); - function LiveDictStore(type) { DictStore.call(this); LiveStoreMixin.call(this, type); @@ -146,10 +91,6 @@ function LiveDictStore(type) { _.extend(LiveDictStore.prototype, DictStore.prototype, LiveStoreMixin.prototype); -export function FlowStore() { - return new LiveListStore(ActionTypes.FLOW_STORE); -} - export function SettingsStore() { return new LiveDictStore(ActionTypes.SETTINGS_STORE); }
\ No newline at end of file diff --git a/web/src/js/store/view.js b/web/src/js/store/view.js index d8aeba60..e69de29b 100644 --- a/web/src/js/store/view.js +++ b/web/src/js/store/view.js @@ -1,111 +0,0 @@ -import {EventEmitter} from 'events'; -import _ from "lodash"; - -import utils from "../utils.js"; - -function SortByStoreOrder(elem) { - return this.store.index(elem.id); -} - -var default_sort = SortByStoreOrder; -var default_filt = function (elem) { - return true; -}; - -export function StoreView(store, filt, sortfun) { - EventEmitter.call(this); - - this.store = store; - - this.add = this.add.bind(this); - this.update = this.update.bind(this); - this.remove = this.remove.bind(this); - this.recalculate = this.recalculate.bind(this); - this.store.addListener("add", this.add); - this.store.addListener("update", this.update); - this.store.addListener("remove", this.remove); - this.store.addListener("recalculate", this.recalculate); - - this.recalculate(filt, sortfun); -} - -_.extend(StoreView.prototype, EventEmitter.prototype, { - close: function () { - this.store.removeListener("add", this.add); - this.store.removeListener("update", this.update); - this.store.removeListener("remove", this.remove); - this.store.removeListener("recalculate", this.recalculate); - this.removeAllListeners(); - }, - recalculate: function (filt, sortfun) { - filt = filt || this.filt || default_filt; - sortfun = sortfun || this.sortfun || default_sort; - filt = filt.bind(this); - sortfun = sortfun.bind(this); - this.filt = filt; - this.sortfun = sortfun; - - this.list = this.store.list.filter(filt); - this.list.sort(function (a, b) { - var akey = sortfun(a); - var bkey = sortfun(b); - if(akey < bkey){ - return -1; - } else if(akey > bkey){ - return 1; - } else { - return 0; - } - }); - this.emit("recalculate"); - }, - indexOf: function (elem) { - return this.list.indexOf(elem, _.sortedIndexBy(this.list, elem, this.sortfun)); - }, - add: function (elem) { - if (this.filt(elem)) { - var idx = _.sortedIndexBy(this.list, elem, this.sortfun); - if (idx === this.list.length) { //happens often, .push is way faster. - this.list.push(elem); - } else { - this.list.splice(idx, 0, elem); - } - this.emit("add", elem, idx); - } - }, - update: function (elem) { - var idx; - var i = this.list.length; - // Search from the back, we usually update the latest entries. - while (i--) { - if (this.list[i].id === elem.id) { - idx = i; - break; - } - } - - if (idx === -1) { //not contained in list - this.add(elem); - } else if (!this.filt(elem)) { - this.remove(elem.id); - } else { - if (this.sortfun(this.list[idx]) !== this.sortfun(elem)) { //sortpos has changed - this.remove(this.list[idx]); - this.add(elem); - } else { - this.list[idx] = elem; - this.emit("update", elem, idx); - } - } - }, - remove: function (elem_id) { - var idx = this.list.length; - while (idx--) { - if (this.list[idx].id === elem_id) { - this.list.splice(idx, 1); - this.emit("remove", elem_id, idx); - break; - } - } - } -}); |