From e4ee3e0236069873332fff13baefe4f676e289ee Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Tue, 16 Sep 2014 21:06:30 +1200 Subject: Convert to ES5 inheritance pattern --- web/src/js/stores/base.js | 48 +++++++++++++++++---------------- web/src/js/stores/eventlogstore.js | 54 +++++++++++++++++++++----------------- web/src/js/stores/settingstore.js | 31 ++++++++++++---------- 3 files changed, 72 insertions(+), 61 deletions(-) (limited to 'web/src/js/stores') diff --git a/web/src/js/stores/base.js b/web/src/js/stores/base.js index 55808deb..c02c77b6 100644 --- a/web/src/js/stores/base.js +++ b/web/src/js/stores/base.js @@ -1,24 +1,26 @@ -function EventEmitter() {"use strict"; - this.listeners = {}; +"use strict"; + +function EventEmitter() { + this.listeners = {}; +} +EventEmitter.prototype.emit=function(event) { + if (!(event in this.listeners)) { + return; } - EventEmitter.prototype.emit=function(event) {"use strict"; - if (!(event in this.listeners)) { - return; - } - this.listeners[event].forEach(function(listener) { - listener.apply(this, arguments); - }.bind(this)); - }; - EventEmitter.prototype.addListener=function(event, f) {"use strict"; - this.listeners[event] = this.listeners[event] || []; - this.listeners[event].push(f); - }; - EventEmitter.prototype.removeListener=function(event, f) {"use strict"; - if (!(event in this.listeners)) { - return false; - } - var index = this.listeners[event].indexOf(f); - if (index >= 0) { - this.listeners[event].splice(index, 1); - } - }; + this.listeners[event].forEach(function(listener) { + listener.apply(this, arguments); + }.bind(this)); +}; +EventEmitter.prototype.addListener=function(event, f) { + this.listeners[event] = this.listeners[event] || []; + this.listeners[event].push(f); +}; +EventEmitter.prototype.removeListener=function(event, f) { + if (!(event in this.listeners)) { + return false; + } + var index = this.listeners[event].indexOf(f); + if (index >= 0) { + this.listeners[event].splice(index, 1); + } +}; diff --git a/web/src/js/stores/eventlogstore.js b/web/src/js/stores/eventlogstore.js index f9d8cf27..dbecc749 100644 --- a/web/src/js/stores/eventlogstore.js +++ b/web/src/js/stores/eventlogstore.js @@ -1,3 +1,4 @@ +"use strict"; // // We have an EventLogView and an EventLogStore: // The basic architecture is that one can request views on the event log @@ -5,41 +6,44 @@ // The view object is accessed by React components and distributes updates etc. // // See also: components/EventLog.react.js +function EventLogView(store, live) { + EventEmitter.call(this); + this.$EventLogView_store = store; + this.live = live; + this.log = []; -for(var EventEmitter____Key in EventEmitter){if(EventEmitter.hasOwnProperty(EventEmitter____Key)){EventLogView[EventEmitter____Key]=EventEmitter[EventEmitter____Key];}}var ____SuperProtoOfEventEmitter=EventEmitter===null?null:EventEmitter.prototype;EventLogView.prototype=Object.create(____SuperProtoOfEventEmitter);EventLogView.prototype.constructor=EventLogView;EventLogView.__superConstructor__=EventEmitter; - function EventLogView(store, live) {"use strict"; - EventEmitter.call(this); - this.$EventLogView_store = store; - this.live = live; - this.log = []; + this.add = this.add.bind(this); - this.add = this.add.bind(this); - - if (live) { - this.$EventLogView_store.addListener("new_entry", this.add); - } + if (live) { + this.$EventLogView_store.addListener("new_entry", this.add); } - EventLogView.prototype.close=function() {"use strict"; +} +_.extend(EventLogView.prototype, EventEmitter.prototype, { + close: function() { this.$EventLogView_store.removeListener("new_entry", this.add); - }; - EventLogView.prototype.getAll=function() {"use strict"; + }, + getAll: function() { return this.log; - }; - EventLogView.prototype.add=function(entry) {"use strict"; + }, + add: function(entry) { this.log.push(entry); this.emit("change"); - }; - EventLogView.prototype.add_bulk=function(messages) {"use strict"; + }, + add_bulk: function(messages) { var log = messages; var last_id = log[log.length - 1].id; var to_add = _.filter(this.log, function(entry) {return entry.id > last_id;}); this.log = log.concat(to_add); this.emit("change"); - }; + } +}); -for(EventEmitter____Key in EventEmitter){if(EventEmitter.hasOwnProperty(EventEmitter____Key)){_EventLogStore[EventEmitter____Key]=EventEmitter[EventEmitter____Key];}}_EventLogStore.prototype=Object.create(____SuperProtoOfEventEmitter);_EventLogStore.prototype.constructor=_EventLogStore;_EventLogStore.__superConstructor__=EventEmitter;function _EventLogStore(){"use strict";if(EventEmitter!==null){EventEmitter.apply(this,arguments);}} - _EventLogStore.prototype.getView=function(since) {"use strict"; +function _EventLogStore(){ + EventEmitter.call(this); +} +_.extend(_EventLogStore.prototype, EventEmitter.prototype, { + getView: function(since) { var view = new EventLogView(this, !since); //TODO: Really do bulk retrieval of last messages. @@ -69,8 +73,8 @@ for(EventEmitter____Key in EventEmitter){if(EventEmitter.hasOwnProperty(EventEmi }); }, 1000); return view; - }; - _EventLogStore.prototype.handle=function(action) {"use strict"; + }, + handle: function(action) { switch (action.actionType) { case ActionTypes.EVENTLOG_ADD: this.emit("new_message", action.message); @@ -78,7 +82,9 @@ for(EventEmitter____Key in EventEmitter){if(EventEmitter.hasOwnProperty(EventEmi default: return; } - }; + } +}); + var EventLogStore = new _EventLogStore(); AppDispatcher.register(EventLogStore.handle.bind(EventLogStore)); diff --git a/web/src/js/stores/settingstore.js b/web/src/js/stores/settingstore.js index 5ceed7db..9139076e 100644 --- a/web/src/js/stores/settingstore.js +++ b/web/src/js/stores/settingstore.js @@ -1,18 +1,20 @@ -for(var EventEmitter____Key in EventEmitter){if(EventEmitter.hasOwnProperty(EventEmitter____Key)){_SettingsStore[EventEmitter____Key]=EventEmitter[EventEmitter____Key];}}var ____SuperProtoOfEventEmitter=EventEmitter===null?null:EventEmitter.prototype;_SettingsStore.prototype=Object.create(____SuperProtoOfEventEmitter);_SettingsStore.prototype.constructor=_SettingsStore;_SettingsStore.__superConstructor__=EventEmitter; - function _SettingsStore() {"use strict"; - EventEmitter.call(this); +"use strict"; - //FIXME: What do we do if we haven't requested anything from the server yet? - this.settings = { - version: "0.12", - showEventLog: true, - mode: "transparent", - }; - } - _SettingsStore.prototype.getAll=function() {"use strict"; +function _SettingsStore() { + EventEmitter.call(this); + + //FIXME: What do we do if we haven't requested anything from the server yet? + this.settings = { + version: "0.12", + showEventLog: true, + mode: "transparent", + }; +} +_.extend(_SettingsStore.prototype, EventEmitter.prototype, { + getAll: function() { return this.settings; - }; - _SettingsStore.prototype.handle=function(action) {"use strict"; + }, + handle: function(action) { switch (action.actionType) { case ActionTypes.SETTINGS_UPDATE: this.settings = action.settings; @@ -21,7 +23,8 @@ for(var EventEmitter____Key in EventEmitter){if(EventEmitter.hasOwnProperty(Even default: return; } - }; + } +}); var SettingsStore = new _SettingsStore(); AppDispatcher.register(SettingsStore.handle.bind(SettingsStore)); -- cgit v1.2.3