cry-synced-db-client 0.1.57 → 0.1.58

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/dist/index.js CHANGED
@@ -467,6 +467,8 @@ class CrossTabSyncManager {
467
467
  broadcastMetaUpdate(updates) {
468
468
  if (!this.metaUpdateChannel)
469
469
  return;
470
+ if (!this.deps.isLeader())
471
+ return;
470
472
  for (const [collection, ids] of Object.entries(updates)) {
471
473
  let existing = this.pendingBroadcasts.get(collection);
472
474
  if (!existing) {
@@ -2742,6 +2744,7 @@ class SyncedDb {
2742
2744
  },
2743
2745
  deps: {
2744
2746
  isInitialized: () => this.initialized,
2747
+ isLeader: () => this.leaderElection.isLeader(),
2745
2748
  getCollections: () => this.collections,
2746
2749
  dexieDb: this.dexieDb,
2747
2750
  writeToInMemBatch: (collection, items, operation) => {
@@ -26,6 +26,7 @@ export declare class CrossTabSyncManager implements I_CrossTabSyncManager {
26
26
  init(): void;
27
27
  /**
28
28
  * Broadcast updated IDs to other tabs (debounced).
29
+ * Only the leader should broadcast.
29
30
  */
30
31
  broadcastMetaUpdate(updates: Record<string, string[]>): void;
31
32
  /**
@@ -42,6 +42,8 @@ export interface CrossTabSyncCallbacks {
42
42
  export interface CrossTabSyncDeps {
43
43
  /** Check if SyncedDb is initialized. */
44
44
  isInitialized: () => boolean;
45
+ /** Check if this tab is the leader. */
46
+ isLeader: () => boolean;
45
47
  /** Get collections map. */
46
48
  getCollections: () => Map<string, CollectionConfig>;
47
49
  /** DexieDb instance. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cry-synced-db-client",
3
- "version": "0.1.57",
3
+ "version": "0.1.58",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",