@vanillaspa/event-bus 1.3.1 → 1.3.3
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 +4 -4
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export const name =
|
|
2
|
-
const channel = new BroadcastChannel();
|
|
1
|
+
export const name = 'eventbus';
|
|
2
|
+
const channel = new BroadcastChannel('eventbus');
|
|
3
3
|
const contextListeners = new WeakMap(); // context - Map<type, listener[]>
|
|
4
4
|
|
|
5
5
|
channel.onmessage = ({ data }) => {
|
|
@@ -31,7 +31,7 @@ export function addEventListener(type, listener, context = undefined) {
|
|
|
31
31
|
if (!byType.has(type)) byType.set(type, []);
|
|
32
32
|
byType.get(type).push(listener);
|
|
33
33
|
} else {
|
|
34
|
-
if (context) throw new Error(
|
|
34
|
+
if (context) throw new Error('Syntax error: context must be an object.');
|
|
35
35
|
if (typeof window !== 'undefined') window.addEventListener(type, listener);
|
|
36
36
|
}
|
|
37
37
|
}
|
|
@@ -49,7 +49,7 @@ export function removeEventListener(type, listener, context = undefined) {
|
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
export function dispatchEvent(event) {
|
|
52
|
+
export function dispatchEvent(event, context = undefined) {
|
|
53
53
|
dispatchLocally(event, context);
|
|
54
54
|
channel.postMessage({
|
|
55
55
|
type: event.type,
|
package/package.json
CHANGED