MCPcopy Create free account
hub / github.com/TanStack/db / createTodos

Function createTodos

examples/electron/offline-first/src/db/todos.ts:241–279  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

239
240// Create todos setup: collection + offline executor
241export function createTodos() {
242 const executor = startOfflineExecutor({
243 collections: { todos: collection },
244 storage: new ElectronSQLiteStorageAdapter('offline-tx:'),
245 mutationFns: {
246 syncTodos,
247 },
248 onLeadershipChange: (isLeader) => {
249 console.log('[Offline] Leadership changed:', isLeader)
250 },
251 onStorageFailure: (diagnostic) => {
252 console.warn('[Offline] Storage failure:', diagnostic)
253 },
254 })
255
256 console.log('[Offline] Executor mode:', executor.mode)
257
258 // Log when initialization completes and pending transactions are loaded
259 executor
260 .waitForInit()
261 .then(() => {
262 console.log(
263 '[Offline] Init complete. isOfflineEnabled:',
264 executor.isOfflineEnabled,
265 )
266 console.log('[Offline] Pending count:', executor.getPendingCount())
267 })
268 .catch((err) => {
269 console.error('[Offline] Init failed:', err)
270 })
271
272 return {
273 collection,
274 executor,
275 close: () => {
276 executor.dispose()
277 },
278 }
279}
280
281// Helper to create offline actions
282export function createTodoActions(

Callers 1

AppFunction · 0.90

Calls 4

startOfflineExecutorFunction · 0.90
waitForInitMethod · 0.80
getPendingCountMethod · 0.45
disposeMethod · 0.45

Tested by

no test coverage detected