diff options
author | Maximilian Hils <git@maximilianhils.com> | 2014-09-17 02:13:37 +0200 |
---|---|---|
committer | Maximilian Hils <git@maximilianhils.com> | 2014-09-17 02:13:37 +0200 |
commit | 51db9a5612f0899ed61751dbee3f4e4b19a74ea4 (patch) | |
tree | b1c7f9950f496c8216050b57b1f0e06c6eeb5424 /web/src/js/stores | |
parent | d998790c2f12594e6d0edc5a98e908677b60b31f (diff) | |
download | mitmproxy-51db9a5612f0899ed61751dbee3f4e4b19a74ea4.tar.gz mitmproxy-51db9a5612f0899ed61751dbee3f4e4b19a74ea4.tar.bz2 mitmproxy-51db9a5612f0899ed61751dbee3f4e4b19a74ea4.zip |
formatting
Diffstat (limited to 'web/src/js/stores')
-rw-r--r-- | web/src/js/stores/base.js | 9 | ||||
-rw-r--r-- | web/src/js/stores/eventlogstore.js | 39 | ||||
-rw-r--r-- | web/src/js/stores/settingstore.js | 7 |
3 files changed, 29 insertions, 26 deletions
diff --git a/web/src/js/stores/base.js b/web/src/js/stores/base.js index e72141b5..9a2dbd64 100644 --- a/web/src/js/stores/base.js +++ b/web/src/js/stores/base.js @@ -1,20 +1,19 @@ - function EventEmitter() { this.listeners = {}; } -EventEmitter.prototype.emit=function(event) { +EventEmitter.prototype.emit = function (event) { if (!(event in this.listeners)) { return; } - this.listeners[event].forEach(function(listener) { + this.listeners[event].forEach(function (listener) { listener.apply(this, arguments); }.bind(this)); }; -EventEmitter.prototype.addListener=function(event, f) { +EventEmitter.prototype.addListener = function (event, f) { this.listeners[event] = this.listeners[event] || []; this.listeners[event].push(f); }; -EventEmitter.prototype.removeListener=function(event, f) { +EventEmitter.prototype.removeListener = function (event, f) { if (!(event in this.listeners)) { return false; } diff --git a/web/src/js/stores/eventlogstore.js b/web/src/js/stores/eventlogstore.js index 23f8d3ed..54c45939 100644 --- a/web/src/js/stores/eventlogstore.js +++ b/web/src/js/stores/eventlogstore.js @@ -18,42 +18,47 @@ function EventLogView(store, live) { } } _.extend(EventLogView.prototype, EventEmitter.prototype, { - close: function() { + close: function () { this.$EventLogView_store.removeListener("new_entry", this.add); }, - getAll: function() { + getAll: function () { return this.log; }, - add: function(entry) { + add: function (entry) { this.log.push(entry); this.emit("change"); }, - add_bulk: function(messages) { + 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;}); + var to_add = _.filter(this.log, function (entry) { + return entry.id > last_id; + }); this.log = log.concat(to_add); this.emit("change"); } }); -function _EventLogStore(){ +function _EventLogStore() { EventEmitter.call(this); } _.extend(_EventLogStore.prototype, EventEmitter.prototype, { - getView: function(since) { + getView: function (since) { var view = new EventLogView(this, !since); //TODO: Really do bulk retrieval of last messages. - window.setTimeout(function() { - view.add_bulk([{ - id: 1, - message: "Hello World" - }, { - id: 2, - message: "I was already transmitted as an event." - }]); + window.setTimeout(function () { + view.add_bulk([ + { + id: 1, + message: "Hello World" + }, + { + id: 2, + message: "I was already transmitted as an event." + } + ]); }, 100); var id = 2; @@ -65,7 +70,7 @@ _.extend(_EventLogStore.prototype, EventEmitter.prototype, { id: id++, message: "I was only transmitted as an event before the bulk was added.." }); - window.setInterval(function() { + window.setInterval(function () { view.add({ id: id++, message: "." @@ -73,7 +78,7 @@ _.extend(_EventLogStore.prototype, EventEmitter.prototype, { }, 1000); return view; }, - handle: function(action) { + handle: function (action) { switch (action.actionType) { case ActionTypes.EVENTLOG_ADD: this.emit("new_message", action.message); diff --git a/web/src/js/stores/settingstore.js b/web/src/js/stores/settingstore.js index 23ac6dca..0ba7d800 100644 --- a/web/src/js/stores/settingstore.js +++ b/web/src/js/stores/settingstore.js @@ -1,4 +1,3 @@ - function _SettingsStore() { EventEmitter.call(this); @@ -7,13 +6,13 @@ function _SettingsStore() { version: "0.12", showEventLog: true, mode: "transparent", - }; + }; } _.extend(_SettingsStore.prototype, EventEmitter.prototype, { - getAll: function() { + getAll: function () { return this.settings; }, - handle: function(action) { + handle: function (action) { switch (action.actionType) { case ActionTypes.SETTINGS_UPDATE: this.settings = action.settings; |