SignalDB is a local JavaScript database with a MongoDB-like interface and TypeScript support, enabling optimistic UI with signal-based reactivity across multiple frameworks. It integrates easily with libraries like Angular, Solid.js, Preact, and Vue, simplifying data management with schema-less design, in-memory storage, and fast queries.
The SyncManager fails to find the lastFinishedSync when using an async persistence adapter when attempting to start sync soon after creation. This issue only happens with async persistence adapters that might take several ms loading data like an indexeddb persister and not with sync persisters like local storage.
const syncManager = new SyncManager({
persistenceAdapter: (id) => idbPersister(id),
pull: async ({ name, lastFinishedSyncEnd }) => {
// lastFinishedSyncEnd is always undefined on the first sync
const response = await fetch(`/api/collections/${collectionOptions.name}?since=${lastFinishedSyncStart}`)
return await response.json()
},
// ...
})
const collection = new Collection()
syncManager.addCollection(collection, {
name: 'todos',
})
syncManager.sync('todos') // will always load all the data instead of just data since `lastFinishedSyncEnd`
My current workaround is to delay calling sync or syncAll until syncManager.syncOperations, syncManager.changes, syncManager.remoteChanges, and syncManager.snapshots have all emitted the persistence.pullCompleted event once. This is not ideal because I'm using private properties. Ideally, the sync manager would emit some type of ready or init event once its internal collections have all loaded into memory.
The
SyncManager
fails to find thelastFinishedSync
when using an async persistence adapter when attempting to start sync soon after creation. This issue only happens with async persistence adapters that might take several ms loading data like anindexeddb persister
and not with sync persisters like local storage.My current workaround is to delay calling
sync
orsyncAll
untilsyncManager.syncOperations
,syncManager.changes
,syncManager.remoteChanges
, andsyncManager.snapshots
have all emitted thepersistence.pullCompleted
event once. This is not ideal because I'm using private properties. Ideally, the sync manager would emit some type ofready
orinit
event once its internal collections have all loaded into memory.