@lijuhong1981/jsevents 1.2.13 → 1.2.14
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 +4 -4
- package/src/EventDispatcher.js +5 -1
- package/src/EventSubscriber.js +4 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lijuhong1981/jsevents",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.14",
|
|
4
4
|
"description": "Event system with EventDispatcher, EventEmitter and EventSubscriber.",
|
|
5
5
|
"author": "lijuhong1981 <lijuhong@hotmail.com>",
|
|
6
6
|
"homepage": "https://github.com/lijuhong1981/jslibs#readme",
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
"url": "https://github.com/lijuhong1981/jslibs/issues"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@lijuhong1981/jscheck": "^1.1.
|
|
23
|
-
"@lijuhong1981/jsdestroy": "^1.2.
|
|
22
|
+
"@lijuhong1981/jscheck": "^1.1.8",
|
|
23
|
+
"@lijuhong1981/jsdestroy": "^1.2.8"
|
|
24
24
|
},
|
|
25
|
-
"gitHead": "
|
|
25
|
+
"gitHead": "5d4bd57b654be98c46364160070d5dd11600afa6"
|
|
26
26
|
}
|
package/src/EventDispatcher.js
CHANGED
|
@@ -33,6 +33,10 @@ function removeListener(events, type, callback) {
|
|
|
33
33
|
if (event) {
|
|
34
34
|
if (callback) {
|
|
35
35
|
event.removeEventListener(callback);
|
|
36
|
+
if (event.numberOfListeners === 0) {
|
|
37
|
+
events.delete(type);
|
|
38
|
+
event.destroy();
|
|
39
|
+
}
|
|
36
40
|
} else {
|
|
37
41
|
events.delete(type);
|
|
38
42
|
event.destroy();
|
|
@@ -147,7 +151,7 @@ class EventDispatcher extends Destroyable {
|
|
|
147
151
|
|
|
148
152
|
const event = this._events.get(type);
|
|
149
153
|
|
|
150
|
-
return event && event.numberOfListeners > 0;
|
|
154
|
+
return !!(event && event.numberOfListeners > 0);
|
|
151
155
|
}
|
|
152
156
|
|
|
153
157
|
/**
|
package/src/EventSubscriber.js
CHANGED
|
@@ -2,8 +2,8 @@ import Check from "@lijuhong1981/jscheck/src/Check.js";
|
|
|
2
2
|
import Destroyable from "@lijuhong1981/jsdestroy/src/Destroyable.js";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
5
|
+
* 用于管理某个事件的订阅者的通用工具类。该类通常在容器类内部实例化,并作为属性暴露给其他对象以进行订阅。
|
|
6
|
+
*
|
|
7
7
|
* @class EventSubscriber
|
|
8
8
|
* @extends Destroyable
|
|
9
9
|
*/
|
|
@@ -134,11 +134,11 @@ class EventSubscriber extends Destroyable {
|
|
|
134
134
|
* @returns {this}
|
|
135
135
|
*/
|
|
136
136
|
raiseEvent(...args) {
|
|
137
|
-
const listeners = this._listenersMap.values();
|
|
137
|
+
const listeners = Array.from(this._listenersMap.values());
|
|
138
138
|
for (const listener of listeners) {
|
|
139
139
|
const options = listener.options;
|
|
140
140
|
const callback = listener.callback;
|
|
141
|
-
callback.apply(options.scope,
|
|
141
|
+
callback.apply(options.scope, args);
|
|
142
142
|
if (options.once) {
|
|
143
143
|
this._listenersMap.delete(callback);
|
|
144
144
|
}
|