Skip to content

Commit a5cdb12

Browse files
committed
[sync] Broadcast onSend and onReceive
1 parent 4418620 commit a5cdb12

File tree

4 files changed

+24
-3
lines changed

4 files changed

+24
-3
lines changed

src/@types/synchronizers/synchronizer-broadcast-channel/docs.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,17 @@
5757
* As well as providing a reference to the MergeableStore to persist, you must
5858
* provide a channel name, used by all the browser tabs, workers, or contexts
5959
* that need to synchronize together.
60+
*
61+
* A final set of optional handlers can be provided to help debug sends,
62+
* receives, and errors respectively.
6063
* @param store The MergeableStore to synchronize.
6164
* @param channelName The name of the channel to use.
65+
* @param onSend An optional handler for the messages that this Synchronizer
66+
* sends. This is suitable for debugging synchronization issues in a development
67+
* environment, since v5.1.
68+
* @param onReceive An optional handler for the messages that this Synchronizer
69+
* receives. This is suitable for debugging synchronization issues in a
70+
* development environment, since v5.1.
6271
* @param onIgnoredError An optional handler for the errors that the
6372
* Synchronizer would otherwise ignore when trying to synchronize data. This is
6473
* suitable for debugging synchronization issues in a development environment.

src/@types/synchronizers/synchronizer-broadcast-channel/index.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/// synchronizer-broadcast-channel
22

3+
import type {Receive, Send, Synchronizer} from '../index.d.ts';
34
import type {MergeableStore} from '../../mergeable-store/index.d.ts';
4-
import type {Synchronizer} from '../index.d.ts';
55

66
/// BroadcastChannelSynchronizer
77
export interface BroadcastChannelSynchronizer extends Synchronizer {
@@ -13,5 +13,7 @@ export interface BroadcastChannelSynchronizer extends Synchronizer {
1313
export function createBroadcastChannelSynchronizer(
1414
store: MergeableStore,
1515
channelName: string,
16+
onSend?: Send,
17+
onReceive?: Receive,
1618
onIgnoredError?: (error: any) => void,
1719
): BroadcastChannelSynchronizer;

src/@types/synchronizers/synchronizer-broadcast-channel/with-schemas/index.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/// synchronizer-broadcast-channel
22

3+
import type {Receive, Send, Synchronizer} from '../../with-schemas/index.d.ts';
34
import type {MergeableStore} from '../../../mergeable-store/with-schemas/index.d.ts';
45
import type {OptionalSchemas} from '../../../store/with-schemas/index.d.ts';
5-
import type {Synchronizer} from '../../with-schemas/index.d.ts';
66

77
/// BroadcastChannelSynchronizer
88
export interface BroadcastChannelSynchronizer<Schemas extends OptionalSchemas>
@@ -17,5 +17,7 @@ export function createBroadcastChannelSynchronizer<
1717
>(
1818
store: MergeableStore<Schemas>,
1919
channelName: string,
20+
onSend?: Send,
21+
onReceive?: Receive,
2022
onIgnoredError?: (error: any) => void,
2123
): BroadcastChannelSynchronizer<Schemas>;

src/synchronizers/synchronizer-broadcast-channel/index.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import type {Message, Receive} from '../../@types/synchronizers/index.d.ts';
1+
import type {
2+
Message,
3+
Receive,
4+
Send,
5+
} from '../../@types/synchronizers/index.d.ts';
26
import type {IdOrNull} from '../../@types/common/index.d.ts';
37
import type {MergeableStore} from '../../@types/mergeable-store/index.d.ts';
48
import type {createBroadcastChannelSynchronizer as createBroadcastChannelSynchronizerDecl} from '../../@types/synchronizers/synchronizer-broadcast-channel/index.d.ts';
@@ -9,6 +13,8 @@ import {isUndefined} from '../../common/other.ts';
913
export const createBroadcastChannelSynchronizer = ((
1014
store: MergeableStore,
1115
channelName: string,
16+
onSend?: Send,
17+
onReceive?: Receive,
1218
onIgnoredError?: (error: any) => void,
1319
) => {
1420
const clientId = getUniqueId();
@@ -41,6 +47,8 @@ export const createBroadcastChannelSynchronizer = ((
4147
registerReceive,
4248
destroy,
4349
0.01,
50+
onSend,
51+
onReceive,
4452
onIgnoredError,
4553
{getChannelName: () => channelName},
4654
);

0 commit comments

Comments
 (0)