-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
66 lines (58 loc) · 1.85 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/**
* ListenerManager for managing events!
*/
module.exports = ListenerManager;
function ListenerManager() {
this._listenerCount = 0;
this.timeoutIds = {};
this.intervalIds = {};
this.listenerInfos = {};
}
ListenerManager.prototype.clearAll = function () {
for (var timeoutId in this.timeoutIds) {
console.log(timeoutId);
console.log(timeoutId.id);
// clearTimeout(timeoutId);
}
for (var intervalId in this.intervalIds) {
clearInterval(intervalId);
}
for (var listenerId in this.listenerInfos) {
var info = this.listenerInfos[listenerId];
info.obj.removeListener(info.event, info.cb);
}
this.timeoutIds = {};
this.intervalIds = {};
this.listenerInfos = {};
};
ListenerManager.prototype.clearTimeout = function (timeoutId) {
clearTimeout(timeoutId);
delete this.timeoutIds[timeoutId];
};
ListenerManager.prototype.setTimeout = function (cb, timeout) {
var timeoutId = setTimeout(cb, timeout);
console.log(timeoutId);
this.timeoutIds[timeoutId] = true;
};
ListenerManager.prototype.clearInterval = function (intervalId) {
clearInterval(intervalId);
delete this.timeoutIds[intervalId];
};
ListenerManager.prototype.setInterval = function (cb, interval) {
var intervalId = setTimeout(cb, interval);
this.intervalIds[intervalId] = true;
};
ListenerManager.prototype.clearListener = function (listenerId) {
var listenerInfo = this.listenerInfos[listenerId];
listenerInfo.obj.removeListener(listenerInfo.event, listenerInfo.cb);
delete this.listenerInfos[listenerId];
};
ListenerManager.prototype.setListener = function (obj, event, cb) {
obj.addListener(event, cb);
var listenerInfo = {
obj: obj,
event: event,
cb: cb
};
this.listenerInfos[this._listenerCount++] = listenerInfo;
};