@lijuhong1981/jsevents 1.0.12 → 1.1.1
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/package.json +3 -2
- package/src/EventDispatcher.js +26 -0
- package/src/EventEmitter.js +18 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lijuhong1981/jsevents",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "> TODO: description",
|
|
5
5
|
"author": "lijuhong1981",
|
|
6
6
|
"homepage": "https://github.com/lijuhong1981/jslibs#readme",
|
|
@@ -21,5 +21,6 @@
|
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@lijuhong1981/jscheck": "^1.0.9",
|
|
23
23
|
"@lijuhong1981/jsdestroy": "^1.1.7"
|
|
24
|
-
}
|
|
24
|
+
},
|
|
25
|
+
"gitHead": "a9d2c98fdcce71031b0e4e9c2fabdaab688c7c48"
|
|
25
26
|
}
|
package/src/EventDispatcher.js
CHANGED
|
@@ -104,6 +104,32 @@ class EventDispatcher extends Destroyable {
|
|
|
104
104
|
return this;
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
+
/**
|
|
108
|
+
* 获取某类型事件监听器数量
|
|
109
|
+
* @param {String|Object} type 事件类型
|
|
110
|
+
* @returns {Number} 监听器数量
|
|
111
|
+
*/
|
|
112
|
+
getEventListenersNumber(type) {
|
|
113
|
+
Check.valid('type', type);
|
|
114
|
+
|
|
115
|
+
const listeners = this._listenersMap.get(type);
|
|
116
|
+
|
|
117
|
+
return listeners ? listeners.length : 0;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* 判断是否已添加某类型的事件监听器
|
|
122
|
+
* @param {String|Object} type 事件类型
|
|
123
|
+
* @returns {Boolean} 判断结果
|
|
124
|
+
*/
|
|
125
|
+
hasEventListener(type) {
|
|
126
|
+
Check.valid('type', type);
|
|
127
|
+
|
|
128
|
+
const listeners = this._listenersMap.get(type);
|
|
129
|
+
|
|
130
|
+
return listeners && listeners.length > 0;
|
|
131
|
+
}
|
|
132
|
+
|
|
107
133
|
/**
|
|
108
134
|
* 清除所有事件监听
|
|
109
135
|
* @returns {this}
|
package/src/EventEmitter.js
CHANGED
|
@@ -42,6 +42,24 @@ class EventEmitter extends Destroyable {
|
|
|
42
42
|
return this;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
+
/**
|
|
46
|
+
* 判断是否已添加某类型的事件监听
|
|
47
|
+
* @param {String|Object} type 事件类型
|
|
48
|
+
* @returns {Boolean} 判断结果
|
|
49
|
+
*/
|
|
50
|
+
hasListener(type) {
|
|
51
|
+
return this._dispatcher.hasEventListener(type);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* 获取某类型事件监听器数量
|
|
56
|
+
* @param {String|Object} type 事件类型
|
|
57
|
+
* @returns {Number} 监听器数量
|
|
58
|
+
*/
|
|
59
|
+
listenersNumber() {
|
|
60
|
+
return this._dispatcher.getEventListenersNumber(type);
|
|
61
|
+
}
|
|
62
|
+
|
|
45
63
|
/**
|
|
46
64
|
* 清除所有事件监听
|
|
47
65
|
* @returns {this}
|