fix onScreenEvent listeners.
This commit is contained in:
parent
245b3f44b1
commit
3205dd289d
|
@ -2521,21 +2521,19 @@ Element.prototype.sattr = function(style, fg, bg) {
|
||||||
|
|
||||||
Element.prototype.onScreenEvent = function(type, handler) {
|
Element.prototype.onScreenEvent = function(type, handler) {
|
||||||
this.screen.on(type, handler);
|
this.screen.on(type, handler);
|
||||||
this._elisteners = this._elisteners || {};
|
var listeners = this._slisteners = this._slisteners || [];
|
||||||
this._elisteners[this.uid] = this._elisteners[this.uid] || [];
|
listeners.push({ type: type, handler: handler });
|
||||||
this._elisteners[this.uid].push({ type: type, handler: handler });
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Element.prototype.removeScreenEvent = function(type, handler) {
|
Element.prototype.removeScreenEvent = function(type, handler) {
|
||||||
this.screen.removeListener(type, handler);
|
this.screen.removeListener(type, handler);
|
||||||
this._elisteners = this._elisteners || {};
|
var listeners = this._slisteners = this._slisteners || [];
|
||||||
var listeners = this.screen._elisteners[this.uid] || [];
|
|
||||||
for (var i = 0; i < listeners.length; i++) {
|
for (var i = 0; i < listeners.length; i++) {
|
||||||
var listener = listeners[i];
|
var listener = listeners[i];
|
||||||
if (listener.type === type && listener.handler === handler) {
|
if (listener.type === type && listener.handler === handler) {
|
||||||
listeners.splice(i, 1);
|
listeners.splice(i, 1);
|
||||||
if (this.screen._elisteners[this.uid].length === 0) {
|
if (this._slisteners.length === 0) {
|
||||||
delete this.screen._elisteners[this.uid];
|
delete this._slisteners;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -2543,12 +2541,12 @@ Element.prototype.removeScreenEvent = function(type, handler) {
|
||||||
};
|
};
|
||||||
|
|
||||||
Element.prototype.free = function() {
|
Element.prototype.free = function() {
|
||||||
this._elisteners = this._elisteners || {};
|
var listeners = this._slisteners = this._slisteners || [];
|
||||||
var listeners = this.screen._elisteners[this.uid] || [];
|
|
||||||
for (var i = 0; i < listeners.length; i++) {
|
for (var i = 0; i < listeners.length; i++) {
|
||||||
var listener = listeners[i];
|
var listener = listeners[i];
|
||||||
this.screen.removeListener(listener.type, listener.handler);
|
this.screen.removeListener(listener.type, listener.handler);
|
||||||
}
|
}
|
||||||
|
delete this._slisteners;
|
||||||
};
|
};
|
||||||
|
|
||||||
Element.prototype.destroy = function() {
|
Element.prototype.destroy = function() {
|
||||||
|
|
Loading…
Reference in New Issue