Skip to content

Commit 784699e

Browse files
kevin-dpclaude
andcommitted
feat(examples): wire ElectronCollectionCoordinator for cross-window sync
Use ElectronCollectionCoordinator in the Electron todo app so that local mutations are routed through the leader and all windows receive immediate tx:committed notifications, eliminating the flash on insert. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 874f005 commit 784699e

File tree

1 file changed

+8
-0
lines changed
  • examples/electron/offline-first/src/db

1 file changed

+8
-0
lines changed

examples/electron/offline-first/src/db/todos.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { createCollection } from '@tanstack/react-db'
22
import { queryCollectionOptions } from '@tanstack/query-db-collection'
33
import { startOfflineExecutor } from '@tanstack/offline-transactions'
44
import {
5+
ElectronCollectionCoordinator,
56
createElectronSQLitePersistence,
67
persistedCollectionOptions,
78
} from '@tanstack/db-electron-sqlite-persisted-collection'
@@ -117,9 +118,16 @@ const todoSchema = z.object({
117118
updatedAt: z.string(),
118119
})
119120

121+
// Multi-window coordinator: uses BroadcastChannel + Web Locks for
122+
// leader election and cross-window notification (both available in Electron)
123+
const coordinator = new ElectronCollectionCoordinator({
124+
dbName: 'electron-todos',
125+
})
126+
120127
// Create persistence via IPC bridge to the main process SQLite database
121128
const persistence = createElectronSQLitePersistence({
122129
invoke: window.electronAPI.invoke,
130+
coordinator,
123131
})
124132

125133
const BASE_URL = 'http://localhost:3001'

0 commit comments

Comments
 (0)