()
| 239 | |
| 240 | // Create todos setup: collection + offline executor |
| 241 | export 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 |
| 282 | export function createTodoActions( |
no test coverage detected