Replace custom EventEmitter with one from browserify

This commit is contained in:
Aldo Cortesi 2015-01-01 16:41:45 +13:00
parent fa77fba37c
commit b09dbbe209
5 changed files with 343 additions and 100 deletions

File diff suppressed because one or more lines are too long

View File

@ -117,6 +117,4 @@ module.exports = {
ConnectionActions: ConnectionActions,
FlowActions: FlowActions,
StoreCmds: StoreCmds
};

View File

@ -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");

View File

@ -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);

View File

@ -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,