@lijuhong1981/jsevents 1.0.3 → 1.0.5
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/README.md +11 -0
- package/package.json +9 -16
- package/src/EventDispatcher.js +5 -5
package/README.md
ADDED
package/package.json
CHANGED
|
@@ -1,25 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lijuhong1981/jsevents",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "",
|
|
3
|
+
"version": "1.0.5",
|
|
4
|
+
"description": "> TODO: description",
|
|
5
|
+
"author": "lijuhong1981",
|
|
6
|
+
"homepage": "https://github.com/lijuhong1981/jslib#readme",
|
|
7
|
+
"license": "ISC",
|
|
8
|
+
"type": "module",
|
|
5
9
|
"main": "index.js",
|
|
6
10
|
"module": "index.js",
|
|
7
|
-
"type": "module",
|
|
8
|
-
"scripts": {
|
|
9
|
-
"test": "echo \"Error: no test specified\" && exit 1"
|
|
10
|
-
},
|
|
11
11
|
"repository": {
|
|
12
12
|
"type": "git",
|
|
13
|
-
"url": "git+https://github.com/lijuhong1981/
|
|
13
|
+
"url": "git+https://github.com/lijuhong1981/jslib.git"
|
|
14
14
|
},
|
|
15
|
-
"author": "lijuhong1981",
|
|
16
|
-
"license": "ISC",
|
|
17
15
|
"bugs": {
|
|
18
|
-
"url": "https://github.com/lijuhong1981/
|
|
19
|
-
},
|
|
20
|
-
"homepage": "https://github.com/lijuhong1981/jsevents#readme",
|
|
21
|
-
"dependencies": {
|
|
22
|
-
"@lijuhong1981/jscheck": "^1.0.4",
|
|
23
|
-
"@lijuhong1981/jsdestroy": "^1.0.9"
|
|
16
|
+
"url": "https://github.com/lijuhong1981/jslib/issues"
|
|
24
17
|
}
|
|
25
|
-
}
|
|
18
|
+
}
|
package/src/EventDispatcher.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import Check, { isArray, isFunction, isString
|
|
1
|
+
import Check, { isArray, isFunction, isString } from "@lijuhong1981/jscheck";
|
|
2
2
|
const { Destroyable } = require("@lijuhong1981/jsdestroy");
|
|
3
3
|
|
|
4
4
|
function indexOfListener(listeners, callback) {
|
|
@@ -61,7 +61,7 @@ class EventDispatcher extends Destroyable {
|
|
|
61
61
|
* @returns {this}
|
|
62
62
|
*/
|
|
63
63
|
addEventListener(type, callback, options) {
|
|
64
|
-
Check.
|
|
64
|
+
Check.valid('type', type);
|
|
65
65
|
Check.typeOf.func('callback', callback);
|
|
66
66
|
|
|
67
67
|
if (isString(type) && type.match(/\s+/)) {
|
|
@@ -85,7 +85,7 @@ class EventDispatcher extends Destroyable {
|
|
|
85
85
|
* @returns {this}
|
|
86
86
|
*/
|
|
87
87
|
removeEventListener(type, callback) {
|
|
88
|
-
Check.
|
|
88
|
+
Check.valid('type', type);
|
|
89
89
|
|
|
90
90
|
if (isString(type) && type.match(/\s+/)) {
|
|
91
91
|
type = type.split(/\s+/);
|
|
@@ -121,7 +121,7 @@ class EventDispatcher extends Destroyable {
|
|
|
121
121
|
* @returns {this}
|
|
122
122
|
*/
|
|
123
123
|
dispatch(type, ...args) {
|
|
124
|
-
Check.
|
|
124
|
+
Check.valid('type', type);
|
|
125
125
|
|
|
126
126
|
const listeners = this._listenersMap.get(type);
|
|
127
127
|
if (listeners && listeners.length > 0) {
|
|
@@ -146,7 +146,7 @@ class EventDispatcher extends Destroyable {
|
|
|
146
146
|
*/
|
|
147
147
|
dispatchEvent(event, owner) {
|
|
148
148
|
Check.typeOf.object('event', event);
|
|
149
|
-
Check.
|
|
149
|
+
Check.valid('event.type', event.type);
|
|
150
150
|
|
|
151
151
|
event.owner = event.owner || owner || this;
|
|
152
152
|
|