Convert to ES5 inheritance pattern

This commit is contained in:
Aldo Cortesi 2014-09-16 21:06:30 +12:00
parent 6efe1aa6a9
commit e4ee3e0236
9 changed files with 231 additions and 213 deletions

View File

@ -52,10 +52,12 @@ var SettingsActions = {
}
};
function EventEmitter() {"use strict";
"use strict";
function EventEmitter() {
this.listeners = {};
}
EventEmitter.prototype.emit=function(event) {"use strict";
EventEmitter.prototype.emit=function(event) {
if (!(event in this.listeners)) {
return;
}
@ -63,11 +65,11 @@ function EventEmitter() {"use strict";
listener.apply(this, arguments);
}.bind(this));
};
EventEmitter.prototype.addListener=function(event, f) {"use strict";
EventEmitter.prototype.addListener=function(event, f) {
this.listeners[event] = this.listeners[event] || [];
this.listeners[event].push(f);
};
EventEmitter.prototype.removeListener=function(event, f) {"use strict";
EventEmitter.prototype.removeListener=function(event, f) {
if (!(event in this.listeners)) {
return false;
}
@ -77,8 +79,9 @@ function EventEmitter() {"use strict";
}
};
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";
"use strict";
function _SettingsStore() {
EventEmitter.call(this);
//FIXME: What do we do if we haven't requested anything from the server yet?
@ -88,10 +91,11 @@ for(var EventEmitter____Key in EventEmitter){if(EventEmitter.hasOwnProperty(Even
mode: "transparent",
};
}
_SettingsStore.prototype.getAll=function() {"use strict";
_.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;
@ -100,11 +104,13 @@ for(var EventEmitter____Key in EventEmitter){if(EventEmitter.hasOwnProperty(Even
default:
return;
}
};
}
});
var SettingsStore = new _SettingsStore();
AppDispatcher.register(SettingsStore.handle.bind(SettingsStore));
"use strict";
//
// We have an EventLogView and an EventLogStore:
// The basic architecture is that one can request views on the event log
@ -112,9 +118,7 @@ AppDispatcher.register(SettingsStore.handle.bind(SettingsStore));
// The view object is accessed by React components and distributes updates etc.
//
// See also: components/EventLog.react.js
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";
function EventLogView(store, live) {
EventEmitter.call(this);
this.$EventLogView_store = store;
this.live = live;
@ -126,27 +130,32 @@ for(var EventEmitter____Key in EventEmitter){if(EventEmitter.hasOwnProperty(Even
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.
@ -176,8 +185,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);
@ -185,7 +194,9 @@ for(EventEmitter____Key in EventEmitter){if(EventEmitter.hasOwnProperty(EventEmi
default:
return;
}
};
}
});
var EventLogStore = new _EventLogStore();
AppDispatcher.register(EventLogStore.handle.bind(EventLogStore));
@ -344,7 +355,7 @@ var TrafficTable = React.createClass({displayName: 'TrafficTable',
i = 12;
while (i--) x += x;
return (
React.DOM.div(null, React.DOM.pre(null, " ", x, " "))
React.DOM.div(null, "Flow")
);
}
});
@ -450,9 +461,7 @@ var ProxyApp = (
);
$(function() {
Connection.init();
app = React.renderComponent(ProxyApp, document.body);
});
//# sourceMappingURL=app.js.map

View File

@ -1,6 +1,4 @@
$(function() {
Connection.init();
app = React.renderComponent(ProxyApp, document.body);
});

View File

@ -28,7 +28,7 @@ var TrafficTable = React.createClass({
i = 12;
while (i--) x += x;
return (
<div><pre> { x } </pre></div>
<div>Flow</div>
);
}
});

View File

@ -1,7 +1,9 @@
function EventEmitter() {"use strict";
"use strict";
function EventEmitter() {
this.listeners = {};
}
EventEmitter.prototype.emit=function(event) {"use strict";
EventEmitter.prototype.emit=function(event) {
if (!(event in this.listeners)) {
return;
}
@ -9,11 +11,11 @@ function EventEmitter() {"use strict";
listener.apply(this, arguments);
}.bind(this));
};
EventEmitter.prototype.addListener=function(event, f) {"use strict";
EventEmitter.prototype.addListener=function(event, f) {
this.listeners[event] = this.listeners[event] || [];
this.listeners[event].push(f);
};
EventEmitter.prototype.removeListener=function(event, f) {"use strict";
EventEmitter.prototype.removeListener=function(event, f) {
if (!(event in this.listeners)) {
return false;
}

View File

@ -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,9 +6,7 @@
// The view object is accessed by React components and distributes updates etc.
//
// See also: components/EventLog.react.js
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";
function EventLogView(store, live) {
EventEmitter.call(this);
this.$EventLogView_store = store;
this.live = live;
@ -19,27 +18,32 @@ for(var EventEmitter____Key in EventEmitter){if(EventEmitter.hasOwnProperty(Even
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));

View File

@ -1,5 +1,6 @@
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";
"use strict";
function _SettingsStore() {
EventEmitter.call(this);
//FIXME: What do we do if we haven't requested anything from the server yet?
@ -9,10 +10,11 @@ for(var EventEmitter____Key in EventEmitter){if(EventEmitter.hasOwnProperty(Even
mode: "transparent",
};
}
_SettingsStore.prototype.getAll=function() {"use strict";
_.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));