@wwawing/event-emitter 3.12.9 → 3.12.11
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/lib/impl/browser/index.js +11 -12
- package/lib/impl/node/index.js +10 -11
- package/module/impl/browser/index.js +11 -13
- package/module/impl/node/index.js +9 -11
- package/package.json +2 -2
|
@@ -1,22 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.BrowserEventEmitter = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
class BrowserEventEmitter {
|
|
5
|
+
constructor(target) {
|
|
6
6
|
this.target = target !== null && target !== void 0 ? target : document.createElement("div");
|
|
7
7
|
}
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
dispatch(eventName, data) {
|
|
9
|
+
const customEvent = new CustomEvent(eventName, { detail: data });
|
|
10
10
|
this.target.dispatchEvent(customEvent);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
}
|
|
12
|
+
addListener(eventName, callback) {
|
|
13
|
+
const wrappedFunction = (event) => callback(event.detail);
|
|
14
14
|
this.target.addEventListener(eventName, wrappedFunction);
|
|
15
15
|
return wrappedFunction;
|
|
16
|
-
}
|
|
17
|
-
|
|
16
|
+
}
|
|
17
|
+
removeListener(eventName, callback) {
|
|
18
18
|
this.target.removeEventListener(eventName, callback);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
}());
|
|
19
|
+
}
|
|
20
|
+
}
|
|
22
21
|
exports.BrowserEventEmitter = BrowserEventEmitter;
|
package/lib/impl/node/index.js
CHANGED
|
@@ -1,21 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.NodeEventEmitter = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
const events_1 = require("events");
|
|
5
|
+
class NodeEventEmitter {
|
|
6
|
+
constructor(target) {
|
|
7
7
|
this.target = target !== null && target !== void 0 ? target : new events_1.EventEmitter();
|
|
8
8
|
}
|
|
9
|
-
|
|
9
|
+
dispatch(eventName, data) {
|
|
10
10
|
this.target.emit(eventName, data);
|
|
11
|
-
}
|
|
12
|
-
|
|
11
|
+
}
|
|
12
|
+
addListener(eventName, callback) {
|
|
13
13
|
this.target.addListener(eventName, callback);
|
|
14
14
|
return callback;
|
|
15
|
-
}
|
|
16
|
-
|
|
15
|
+
}
|
|
16
|
+
removeListener(eventName, callback) {
|
|
17
17
|
this.target.removeListener(eventName, callback);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
}());
|
|
18
|
+
}
|
|
19
|
+
}
|
|
21
20
|
exports.NodeEventEmitter = NodeEventEmitter;
|
|
@@ -1,19 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
export class BrowserEventEmitter {
|
|
2
|
+
constructor(target) {
|
|
3
3
|
this.target = target !== null && target !== void 0 ? target : document.createElement("div");
|
|
4
4
|
}
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
dispatch(eventName, data) {
|
|
6
|
+
const customEvent = new CustomEvent(eventName, { detail: data });
|
|
7
7
|
this.target.dispatchEvent(customEvent);
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
}
|
|
9
|
+
addListener(eventName, callback) {
|
|
10
|
+
const wrappedFunction = (event) => callback(event.detail);
|
|
11
11
|
this.target.addEventListener(eventName, wrappedFunction);
|
|
12
12
|
return wrappedFunction;
|
|
13
|
-
}
|
|
14
|
-
|
|
13
|
+
}
|
|
14
|
+
removeListener(eventName, callback) {
|
|
15
15
|
this.target.removeEventListener(eventName, callback);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
}());
|
|
19
|
-
export { BrowserEventEmitter };
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -1,18 +1,16 @@
|
|
|
1
1
|
import { EventEmitter } from "events";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
export class NodeEventEmitter {
|
|
3
|
+
constructor(target) {
|
|
4
4
|
this.target = target !== null && target !== void 0 ? target : new EventEmitter();
|
|
5
5
|
}
|
|
6
|
-
|
|
6
|
+
dispatch(eventName, data) {
|
|
7
7
|
this.target.emit(eventName, data);
|
|
8
|
-
}
|
|
9
|
-
|
|
8
|
+
}
|
|
9
|
+
addListener(eventName, callback) {
|
|
10
10
|
this.target.addListener(eventName, callback);
|
|
11
11
|
return callback;
|
|
12
|
-
}
|
|
13
|
-
|
|
12
|
+
}
|
|
13
|
+
removeListener(eventName, callback) {
|
|
14
14
|
this.target.removeListener(eventName, callback);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
}());
|
|
18
|
-
export { NodeEventEmitter };
|
|
15
|
+
}
|
|
16
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wwawing/event-emitter",
|
|
3
|
-
"version": "3.12.
|
|
3
|
+
"version": "3.12.11",
|
|
4
4
|
"description": "nodeでもモダンブラウザでもIE11でも使えるすごいEventEmitter",
|
|
5
5
|
"files": [
|
|
6
6
|
"lib",
|
|
@@ -34,5 +34,5 @@
|
|
|
34
34
|
"node": ">=18",
|
|
35
35
|
"npm": ">=8"
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "9cd59237d23c90c4d6c1a9eed2c5eae337948941"
|
|
38
38
|
}
|