Skip to content

Commit

Permalink
fix(store): broadcast channel not defined (toeverything#3222)
Browse files Browse the repository at this point in the history
  • Loading branch information
himself65 committed Jun 27, 2023
1 parent 3cc34af commit f5037c1
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions packages/store/src/providers/broadcast-channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@ import type { EventBasedChannel } from 'async-call-rpc';
import { createAsyncCallRPCProviderCreator } from './async-call-rpc.js';
import type { DocProviderCreator } from './type.js';

class BroadcastMessageChannel
extends BroadcastChannel
implements EventBasedChannel
{
on(eventListener: (data: unknown) => void) {
const f = (e: MessageEvent): void => eventListener(e.data);
this.addEventListener('message', f);
return () => this.removeEventListener('message', f);
}
send(data: unknown) {
super.postMessage(data);
export const createBroadcastChannelProvider: DocProviderCreator = (...args) => {
class BroadcastMessageChannel
extends BroadcastChannel
implements EventBasedChannel
{
on(eventListener: (data: unknown) => void) {
const f = (e: MessageEvent): void => eventListener(e.data);
this.addEventListener('message', f);
return () => this.removeEventListener('message', f);
}
send(data: unknown) {
super.postMessage(data);
}
}
}

export const createBroadcastChannelProvider: DocProviderCreator = (...args) => {
const id: string = args[0];
const channel = new BroadcastMessageChannel(id);
return createAsyncCallRPCProviderCreator('broadcast-channel', channel, {
Expand Down

0 comments on commit f5037c1

Please sign in to comment.