aboutsummaryrefslogtreecommitdiffstats
path: root/web/src/js/stores/EventLogStore.es6.js
diff options
context:
space:
mode:
authorMaximilian Hils <git@maximilianhils.com>2014-09-16 00:56:43 +0200
committerMaximilian Hils <git@maximilianhils.com>2014-09-16 00:56:43 +0200
commit674bc4273e9a2f1a2e41ef977a80219423c7cb51 (patch)
treeb343902da8a0de10f075c46c75f8ad135bc23192 /web/src/js/stores/EventLogStore.es6.js
parentacdd182754625fabcfc2c6ed4bdad8a63bce8ad6 (diff)
downloadmitmproxy-674bc4273e9a2f1a2e41ef977a80219423c7cb51.tar.gz
mitmproxy-674bc4273e9a2f1a2e41ef977a80219423c7cb51.tar.bz2
mitmproxy-674bc4273e9a2f1a2e41ef977a80219423c7cb51.zip
format javascript
Diffstat (limited to 'web/src/js/stores/EventLogStore.es6.js')
-rw-r--r--web/src/js/stores/EventLogStore.es6.js129
1 files changed, 73 insertions, 56 deletions
diff --git a/web/src/js/stores/EventLogStore.es6.js b/web/src/js/stores/EventLogStore.es6.js
index 55401690..e470f44f 100644
--- a/web/src/js/stores/EventLogStore.es6.js
+++ b/web/src/js/stores/EventLogStore.es6.js
@@ -1,67 +1,84 @@
-class EventLogView extends EventEmitter {
- constructor(store, live){
- super();
- this._store = store;
- this.live = live;
- this.log = [];
+//
+// We have an EventLogView and an EventLogStore:
+// The basic architecture is that one can request views on the event log
+// from the store, which returns a view object and then deals with getting the data required for the view.
+// The view object is accessed by React components and distributes updates etc.
+//
+// See also: components/EventLog.react.js
- this.add = this.add.bind(this);
+class EventLogView extends EventEmitter {
+ constructor(store, live) {
+ super();
+ this._store = store;
+ this.live = live;
+ this.log = [];
- if(live){
- this._store.addListener("new_entry", this.add);
- }
-
- }
- close() {
- this._store.removeListener("new_entry", this.add);
- }
- getAll() {
- return this.log;
- }
+ this.add = this.add.bind(this);
- add(entry){
- this.log.push(entry);
- this.emit("change");
- }
- add_bulk(messages){
- var log = messages;
- var last_id = log[log.length-1].id;
- var to_add = _.filter(this.log, entry => entry.id > last_id);
- this.log = log.concat(to_add);
- this.emit("change");
- }
+ if (live) {
+ this._store.addListener("new_entry", this.add);
+ }
+ }
+ close() {
+ this._store.removeListener("new_entry", this.add);
+ }
+ getAll() {
+ return this.log;
+ }
+ add(entry) {
+ this.log.push(entry);
+ this.emit("change");
+ }
+ add_bulk(messages) {
+ var log = messages;
+ var last_id = log[log.length - 1].id;
+ var to_add = _.filter(this.log, entry => entry.id > last_id);
+ this.log = log.concat(to_add);
+ this.emit("change");
+ }
}
class _EventLogStore extends EventEmitter {
- getView(since){
- var view = new EventLogView(this, !since);
-
- //TODO: Really do bulk retrieval of last messages.
+ getView(since) {
+ var view = new EventLogView(this, !since);
- window.setTimeout(function(){
- view.add_bulk([
- { id:1, message: "Hello World"},
- { id:2, message: "I was already transmitted as an event."}
- ]);
- }, 100);
+ //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."
+ }]);
+ }, 100);
- var id = 2;
- view.add({id:id++, message: "I was already transmitted as an event."});
- view.add({id:id++, message: "I was only transmitted as an event before the bulk was added.."});
- window.setInterval(function(){
- view.add({id: id++, message: "."});
- }, 1000);
- return view;
- }
- handle(action) {
- switch (action.actionType) {
- case ActionTypes.EVENTLOG_ADD:
- this.emit("new_message", action.message);
- break;
- default:
- return;
- }
- }
+ var id = 2;
+ view.add({
+ id: id++,
+ message: "I was already transmitted as an event."
+ });
+ view.add({
+ id: id++,
+ message: "I was only transmitted as an event before the bulk was added.."
+ });
+ window.setInterval(function() {
+ view.add({
+ id: id++,
+ message: "."
+ });
+ }, 1000);
+ return view;
+ }
+ handle(action) {
+ switch (action.actionType) {
+ case ActionTypes.EVENTLOG_ADD:
+ this.emit("new_message", action.message);
+ break;
+ default:
+ return;
+ }
+ }
}
var EventLogStore = new _EventLogStore();
AppDispatcher.register(EventLogStore.handle.bind(EventLogStore)); \ No newline at end of file