diff options
Diffstat (limited to 'web/src')
-rw-r--r-- | web/src/js/actions.js | 2 | ||||
-rw-r--r-- | web/src/js/store/store.js | 9 | ||||
-rw-r--r-- | web/src/js/store/view.js | 7 | ||||
-rw-r--r-- | web/src/js/utils.js | 32 |
4 files changed, 10 insertions, 40 deletions
diff --git a/web/src/js/actions.js b/web/src/js/actions.js index ea86c8f3..258501a4 100644 --- a/web/src/js/actions.js +++ b/web/src/js/actions.js @@ -117,6 +117,4 @@ module.exports = { ConnectionActions: ConnectionActions, FlowActions: FlowActions, StoreCmds: StoreCmds - - };
\ No newline at end of file diff --git a/web/src/js/store/store.js b/web/src/js/store/store.js index 3def7723..5024049f 100644 --- a/web/src/js/store/store.js +++ b/web/src/js/store/store.js @@ -1,6 +1,7 @@ var _ = require("lodash"); var $ = require("jquery"); +var EventEmitter = require('events').EventEmitter; var utils = require("../utils.js"); var actions = require("../actions.js"); @@ -8,10 +9,10 @@ var dispatcher = require("../dispatcher.js"); function ListStore() { - utils.EventEmitter.call(this); + EventEmitter.call(this); this.reset(); } -_.extend(ListStore.prototype, utils.EventEmitter.prototype, { +_.extend(ListStore.prototype, EventEmitter.prototype, { add: function (elem) { if (elem.id in this._pos_map) { return; @@ -57,10 +58,10 @@ _.extend(ListStore.prototype, utils.EventEmitter.prototype, { function DictStore() { - utils.EventEmitter.call(this); + EventEmitter.call(this); this.reset(); } -_.extend(DictStore.prototype, utils.EventEmitter.prototype, { +_.extend(DictStore.prototype, EventEmitter.prototype, { update: function (dict) { _.merge(this.dict, dict); this.emit("recalculate"); diff --git a/web/src/js/store/view.js b/web/src/js/store/view.js index e96d1bcc..b5db9287 100644 --- a/web/src/js/store/view.js +++ b/web/src/js/store/view.js @@ -1,5 +1,8 @@ + +var EventEmitter = require('events').EventEmitter; var _ = require("lodash"); + var utils = require("../utils.js"); function SortByStoreOrder(elem) { @@ -12,7 +15,7 @@ var default_filt = function(elem){ }; function StoreView(store, filt, sortfun) { - utils.EventEmitter.call(this); + EventEmitter.call(this); filt = filt || default_filt; sortfun = sortfun || default_sort; @@ -30,7 +33,7 @@ function StoreView(store, filt, sortfun) { this.recalculate(filt, sortfun); } -_.extend(StoreView.prototype, utils.EventEmitter.prototype, { +_.extend(StoreView.prototype, EventEmitter.prototype, { close: function () { this.store.removeListener("add", this.add); this.store.removeListener("update", this.update); diff --git a/web/src/js/utils.js b/web/src/js/utils.js index 583df5ce..d5093702 100644 --- a/web/src/js/utils.js +++ b/web/src/js/utils.js @@ -53,37 +53,6 @@ var formatTimeStamp = function (seconds) { }; -function EventEmitter() { - this.listeners = {}; -} -EventEmitter.prototype.emit = function (event) { - if (!(event in this.listeners)) { - return; - } - var args = Array.prototype.slice.call(arguments, 1); - this.listeners[event].forEach(function (listener) { - listener.apply(this, args); - }.bind(this)); -}; -EventEmitter.prototype.addListener = function (events, f) { - events.split(" ").forEach(function (event) { - this.listeners[event] = this.listeners[event] || []; - this.listeners[event].push(f); - }.bind(this)); -}; -EventEmitter.prototype.removeListener = function (events, f) { - if (!(events in this.listeners)) { - return false; - } - events.split(" ").forEach(function (event) { - var index = this.listeners[event].indexOf(f); - if (index >= 0) { - this.listeners[event].splice(index, 1); - } - }.bind(this)); -}; - - function getCookie(name) { var r = document.cookie.match("\\b" + name + "=([^;]*)\\b"); return r ? r[1] : undefined; @@ -109,7 +78,6 @@ $(document).ajaxError(function (event, jqXHR, ajaxSettings, thrownError) { }); module.exports = { - EventEmitter: EventEmitter, formatSize: formatSize, formatTimeDelta: formatTimeDelta, formatTimeStamp: formatTimeStamp, |