diff options
Diffstat (limited to 'web/src/js/store')
-rw-r--r-- | web/src/js/store/store.js | 38 | ||||
-rw-r--r-- | web/src/js/store/view.js | 18 |
2 files changed, 22 insertions, 34 deletions
diff --git a/web/src/js/store/store.js b/web/src/js/store/store.js index 5024049f..e41b2eef 100644 --- a/web/src/js/store/store.js +++ b/web/src/js/store/store.js @@ -1,11 +1,10 @@ -var _ = require("lodash"); -var $ = require("jquery"); -var EventEmitter = require('events').EventEmitter; +import _ from "lodash"; +import $ from "jquery"; +import {EventEmitter} from 'events'; -var utils = require("../utils.js"); -var actions = require("../actions.js"); -var dispatcher = require("../dispatcher.js"); +import {ActionTypes, StoreCmds} from "../actions.js"; +import {AppDispatcher} from "../dispatcher.js"; function ListStore() { @@ -79,7 +78,7 @@ function LiveStoreMixin(type) { this._fetchxhr = false; this.handle = this.handle.bind(this); - dispatcher.AppDispatcher.register(this.handle); + AppDispatcher.register(this.handle); // Avoid double-fetch on startup. if (!(window.ws && window.ws.readyState === WebSocket.CONNECTING)) { @@ -88,11 +87,11 @@ function LiveStoreMixin(type) { } _.extend(LiveStoreMixin.prototype, { handle: function (event) { - if (event.type === actions.ActionTypes.CONNECTION_OPEN) { + if (event.type === ActionTypes.CONNECTION_OPEN) { return this.fetch(); } if (event.type === this.type) { - if (event.cmd === actions.StoreCmds.RESET) { + if (event.cmd === StoreCmds.RESET) { this.fetch(event.data); } else if (this._updates_before_fetch) { console.log("defer update", event); @@ -103,7 +102,7 @@ _.extend(LiveStoreMixin.prototype, { } }, close: function () { - dispatcher.AppDispatcher.unregister(this.handle); + AppDispatcher.unregister(this.handle); }, fetch: function (data) { console.log("fetch " + this.type); @@ -148,16 +147,16 @@ function LiveDictStore(type) { _.extend(LiveDictStore.prototype, DictStore.prototype, LiveStoreMixin.prototype); -function FlowStore() { - return new LiveListStore(actions.ActionTypes.FLOW_STORE); +export function FlowStore() { + return new LiveListStore(ActionTypes.FLOW_STORE); } -function SettingsStore() { - return new LiveDictStore(actions.ActionTypes.SETTINGS_STORE); +export function SettingsStore() { + return new LiveDictStore(ActionTypes.SETTINGS_STORE); } -function EventLogStore() { - LiveListStore.call(this, actions.ActionTypes.EVENT_STORE); +export function EventLogStore() { + LiveListStore.call(this, ActionTypes.EVENT_STORE); } _.extend(EventLogStore.prototype, LiveListStore.prototype, { fetch: function(){ @@ -172,10 +171,3 @@ _.extend(EventLogStore.prototype, LiveListStore.prototype, { } } }); - - -module.exports = { - EventLogStore: EventLogStore, - SettingsStore: SettingsStore, - FlowStore: FlowStore -};
\ No newline at end of file diff --git a/web/src/js/store/view.js b/web/src/js/store/view.js index d628d46b..d8aeba60 100644 --- a/web/src/js/store/view.js +++ b/web/src/js/store/view.js @@ -1,7 +1,7 @@ -var EventEmitter = require('events').EventEmitter; -var _ = require("lodash"); +import {EventEmitter} from 'events'; +import _ from "lodash"; -var utils = require("../utils.js"); +import utils from "../utils.js"; function SortByStoreOrder(elem) { return this.store.index(elem.id); @@ -12,7 +12,7 @@ var default_filt = function (elem) { return true; }; -function StoreView(store, filt, sortfun) { +export function StoreView(store, filt, sortfun) { EventEmitter.call(this); this.store = store; @@ -59,12 +59,12 @@ _.extend(StoreView.prototype, EventEmitter.prototype, { }); this.emit("recalculate"); }, - index: function (elem) { - return _.sortedIndex(this.list, elem, this.sortfun); + indexOf: function (elem) { + return this.list.indexOf(elem, _.sortedIndexBy(this.list, elem, this.sortfun)); }, add: function (elem) { if (this.filt(elem)) { - var idx = this.index(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 { @@ -109,7 +109,3 @@ _.extend(StoreView.prototype, EventEmitter.prototype, { } } }); - -module.exports = { - StoreView: StoreView -};
\ No newline at end of file |