@vanillaspa/event-bus 1.1.1 → 1.2.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/index.js +3 -6
- package/package.json +5 -3
package/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export const name = "eventbus";
|
|
2
|
-
const worker = new
|
|
2
|
+
const worker = new ServiceWorker(new URL('./eventbusWorker.js', import.meta.url), { type: 'module' });
|
|
3
3
|
worker.port.start();
|
|
4
4
|
|
|
5
5
|
const contextListeners = new WeakMap(); // WeakMap to store listeners per object. Keep it private unless you know what you do.
|
|
@@ -43,15 +43,12 @@ export function removeEventListener(type, listener, context = undefined, options
|
|
|
43
43
|
}
|
|
44
44
|
} else {
|
|
45
45
|
window.removeEventListener(type, listener);
|
|
46
|
-
worker.port.postMessage({
|
|
46
|
+
worker.port.postMessage({ action: 'removeEventListener', type });
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
export function dispatchEvent(event) {
|
|
51
|
-
|
|
52
|
-
if (event instanceof CustomEvent) context = event.detail?.target;
|
|
53
|
-
else context = event.target;
|
|
54
|
-
}
|
|
51
|
+
const context = event instanceof CustomEvent ? event.detail?.target : event.target;
|
|
55
52
|
if (context && contextListeners.has(context)) {
|
|
56
53
|
const byType = contextListeners.get(context);
|
|
57
54
|
byType.get(event.type)?.forEach(handler => handler(event));
|
package/package.json
CHANGED
|
@@ -3,14 +3,16 @@
|
|
|
3
3
|
"bugs": {
|
|
4
4
|
"url": "https://github.com/vanillaspa/event-bus/issues"
|
|
5
5
|
},
|
|
6
|
-
"description": "An
|
|
6
|
+
"description": "An event-bus for vanilla SPA. You can use it with web-components.",
|
|
7
7
|
"homepage": "https://github.com/vanillaspa/event-bus#readme",
|
|
8
8
|
"keywords": [
|
|
9
9
|
"EventBus",
|
|
10
10
|
"JavaScript",
|
|
11
11
|
"Module",
|
|
12
12
|
"Vanilla",
|
|
13
|
-
"
|
|
13
|
+
"ServiceWorker",
|
|
14
|
+
"SPA",
|
|
15
|
+
"WebComponents"
|
|
14
16
|
],
|
|
15
17
|
"license": "Unlicense",
|
|
16
18
|
"main": "index.js",
|
|
@@ -23,5 +25,5 @@
|
|
|
23
25
|
"url": "git+https://github.com/vanillaspa/event-bus.git"
|
|
24
26
|
},
|
|
25
27
|
"type": "module",
|
|
26
|
-
"version": "1.
|
|
28
|
+
"version": "1.2.0"
|
|
27
29
|
}
|