mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-29 19:08:44 +00:00
revert to custom EventEmitter, workaround for #504
It's an EventEmitter issue.
This commit is contained in:
parent
300868edff
commit
fa8fc64ce0
@ -1,8 +1,5 @@
|
||||
|
||||
var EventEmitter = require('events').EventEmitter;
|
||||
var _ = require("lodash");
|
||||
|
||||
|
||||
var utils = require("../utils.js");
|
||||
|
||||
function SortByStoreOrder(elem) {
|
||||
@ -15,7 +12,7 @@ var default_filt = function(elem){
|
||||
};
|
||||
|
||||
function StoreView(store, filt, sortfun) {
|
||||
EventEmitter.call(this);
|
||||
utils.EventEmitter.call(this);
|
||||
filt = filt || default_filt;
|
||||
sortfun = sortfun || default_sort;
|
||||
|
||||
@ -33,7 +30,7 @@ function StoreView(store, filt, sortfun) {
|
||||
this.recalculate(filt, sortfun);
|
||||
}
|
||||
|
||||
_.extend(StoreView.prototype, EventEmitter.prototype, {
|
||||
_.extend(StoreView.prototype, utils.EventEmitter.prototype, {
|
||||
close: function () {
|
||||
this.store.removeListener("add", this.add);
|
||||
this.store.removeListener("update", this.update);
|
||||
|
@ -58,6 +58,35 @@ var formatTimeStamp = function (seconds) {
|
||||
return ts.replace("T", " ").replace("Z", "");
|
||||
};
|
||||
|
||||
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");
|
||||
@ -84,6 +113,7 @@ $(document).ajaxError(function (event, jqXHR, ajaxSettings, thrownError) {
|
||||
});
|
||||
|
||||
module.exports = {
|
||||
EventEmitter: EventEmitter,
|
||||
formatSize: formatSize,
|
||||
formatTimeDelta: formatTimeDelta,
|
||||
formatTimeStamp: formatTimeStamp,
|
||||
|
Loading…
Reference in New Issue
Block a user