srvmanger 1.0.3 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/EventManger.js +100 -1
- package/package.json +1 -1
package/EventManger.js
CHANGED
@@ -1,4 +1,103 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
|
3
|
+
var CallList = (function () {
|
4
|
+
function CallList() {
|
5
|
+
this.List = [];
|
6
|
+
}
|
7
|
+
CallList.prototype.add = function (callBack, caller) {
|
8
|
+
this.List.push({ callBack: callBack, caller: caller });
|
9
|
+
};
|
10
|
+
CallList.prototype.contains = function (callBack, caller) {
|
11
|
+
return this.List.findIndex(function (itm) {
|
12
|
+
return itm.callBack === callBack && itm.caller === caller;
|
13
|
+
}) >= 0;
|
14
|
+
};
|
15
|
+
CallList.prototype.clear = function () {
|
16
|
+
this.List = [];
|
17
|
+
};
|
18
|
+
CallList.prototype.remove = function (callBack, caller) {
|
19
|
+
var index = this.List.findIndex(function (itm) {
|
20
|
+
return itm.callBack === callBack && itm.caller === caller;
|
21
|
+
});
|
22
|
+
if (index < 0) {
|
23
|
+
return false;
|
24
|
+
}
|
25
|
+
else {
|
26
|
+
this.List.splice(index, 1);
|
27
|
+
return true;
|
28
|
+
}
|
29
|
+
};
|
30
|
+
CallList.prototype.fire = function () {
|
31
|
+
var data = [];
|
32
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
33
|
+
data[_i] = arguments[_i];
|
34
|
+
}
|
35
|
+
for (var i = 0; i < this.List.length; i++) {
|
36
|
+
var val = this.List[i];
|
37
|
+
if (N(val) || N(val.callBack)) {
|
38
|
+
this.List.splice(i, 1);
|
39
|
+
}
|
40
|
+
else {
|
41
|
+
if (!N(val.caller)) {
|
42
|
+
var call = val.callBack.bind(null, val.caller);
|
43
|
+
call.apply(void 0, data);
|
44
|
+
}
|
45
|
+
else {
|
46
|
+
val.callBack.apply(val, data);
|
47
|
+
}
|
48
|
+
i++;
|
49
|
+
}
|
50
|
+
}
|
51
|
+
};
|
52
|
+
return CallList;
|
53
|
+
}());
|
54
|
+
function N(v) {
|
55
|
+
return -1 != [null, undefined].indexOf(v);
|
56
|
+
}
|
57
|
+
var EventManger = (function () {
|
58
|
+
function EventManger() {
|
59
|
+
this.eventList = new Map();
|
60
|
+
}
|
61
|
+
EventManger.prototype.add = function (key, func, caller) {
|
62
|
+
if (caller === void 0) { caller = null; }
|
63
|
+
if (this.eventList.has(key)) {
|
64
|
+
var notify = this.eventList.get(key);
|
65
|
+
if (!(notify === null || notify === void 0 ? void 0 : notify.contains(func, caller))) {
|
66
|
+
notify === null || notify === void 0 ? void 0 : notify.add(func, caller);
|
67
|
+
}
|
68
|
+
}
|
69
|
+
else {
|
70
|
+
var notify = new CallList();
|
71
|
+
notify.add(func, caller);
|
72
|
+
this.eventList.set(key, notify);
|
73
|
+
}
|
74
|
+
};
|
75
|
+
EventManger.prototype.remove = function (key, func, caller) {
|
76
|
+
if (caller === void 0) { caller = null; }
|
77
|
+
if (N(func)) {
|
78
|
+
this.eventList.delete(key);
|
79
|
+
return;
|
80
|
+
}
|
81
|
+
if (this.eventList.has(key)) {
|
82
|
+
var notify = this.eventList.get(key);
|
83
|
+
if (notify === null || notify === void 0 ? void 0 : notify.contains(func, caller)) {
|
84
|
+
notify.remove(func, caller);
|
85
|
+
}
|
86
|
+
}
|
87
|
+
};
|
88
|
+
EventManger.prototype.fire = function (key) {
|
89
|
+
var data = [];
|
90
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
91
|
+
data[_i - 1] = arguments[_i];
|
92
|
+
}
|
93
|
+
if (this.eventList.has(key)) {
|
94
|
+
var notify = this.eventList.get(key);
|
95
|
+
notify === null || notify === void 0 ? void 0 : notify.fire.apply(notify, data);
|
96
|
+
}
|
97
|
+
};
|
98
|
+
EventManger.prototype.clear = function () {
|
99
|
+
this.eventList.clear();
|
100
|
+
};
|
101
|
+
return EventManger;
|
102
|
+
}());
|
4
103
|
exports.default = EventManger;
|