@lijuhong1981/jsevents 1.0.11 → 1.1.0

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lijuhong1981/jsevents",
3
- "version": "1.0.11",
3
+ "version": "1.1.0",
4
4
  "description": "> TODO: description",
5
5
  "author": "lijuhong1981",
6
6
  "homepage": "https://github.com/lijuhong1981/jslibs#readme",
@@ -21,6 +21,5 @@
21
21
  "dependencies": {
22
22
  "@lijuhong1981/jscheck": "^1.0.9",
23
23
  "@lijuhong1981/jsdestroy": "^1.1.7"
24
- },
25
- "gitHead": "728afda1d6b6237b89025658bcba18c18d58d94e"
24
+ }
26
25
  }
@@ -2,7 +2,7 @@ import Check from "@lijuhong1981/jscheck/src/Check.js";
2
2
  import isArray from "@lijuhong1981/jscheck/src/isArray.js";
3
3
  import isFunction from "@lijuhong1981/jscheck/src/isFunction.js";
4
4
  import isString from "@lijuhong1981/jscheck/src/isString.js";
5
- import Destroyable from "@liuhong1981/jsdestroy/src/Destroyable.js";
5
+ import Destroyable from "@lijuhong1981/jsdestroy/src/Destroyable.js";
6
6
 
7
7
  function indexOfListener(listeners, callback) {
8
8
  for (let i = 0; i < listeners.length; i++) {
@@ -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}
@@ -1,4 +1,4 @@
1
- import Destroyable from "@liuhong1981/jsdestroy/src/Destroyable.js";
1
+ import Destroyable from "@lijuhong1981/jsdestroy/src/Destroyable.js";
2
2
  import EventDispatcher from "./EventDispatcher.js";
3
3
 
4
4
  class EventEmitter extends Destroyable {
@@ -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
+ has(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}