Request for example using sveltekit #1422
Replies: 1 comment
-
Start by checking the Svelte guide: https://signaldb.js.org/guides/svelte/. However, this guide does not cover syncing with a remote API. For that, refer to the examples in the repository: https://github.com/maxnowack/signaldb/tree/main/examples. These examples use React, but the sync implementation concepts remain the same. Also, review the Sync Documentation: https://signaldb.js.org/sync/. The If the API you’re fetching data from doesn’t use Example: const syncManager = new SyncManager({
pull: async ({ apiPath, lastFinishedSyncStart }) => {
// ...
const response = await fetch(url)
const data = await response.json()
return {
items: data.map(item => ({ id: item._id, ...item })),
}
},
push: async ({ apiPath }, { changes }) => {
const changesWithMongoId = {
added: changes.added.map(item => ({ _id: item.id, ...item })),
modified: changes.modified.map(item => ({ _id: item.id, ...item })),
removed: changes.removed.map(item => ({ _id: item.id, ...item })),
}
// ...
},
}) If Example using IndexedDB for persistence: import createIndexedDBAdapter from '@signaldb/indexeddb'
const syncManager = new SyncManager({
persistenceAdapter: name => createIndexedDBAdapter(name),
}) I hope this solves the majority of your issues. Please let me know if something is still unclear 🙂 |
Beta Was this translation helpful? Give feedback.
-
Greetings Max,
I hope you can help me.
I cannot seem to integrate this very promising library into my Sveltekit project. Without a complete example to reference I keep hitting roadblocks.
If you don't have time to create a complete example, perhaps you can show me where my configuration/understanding is flawed.
My setup includes dependencies:
"@signaldb/core": "^1.2.3",
"@signaldb/indexeddb": "^1.0.0",
"@signaldb/sync": "^1.1.1",
Uncaught (in promise) TypeError: The specifier “@signaldb/devtools” was a bare specifier, but was not remapped to anything. Relative module specifiers must start with “./”, “../” or “/”.
The log output is:
And the IDb data contains multiple entries of the same document from MDb - in other words, only one document ever gets imported to the IDb, not the 414 items that are received from MDb:
Any help you can provide would be enormously appreciated.
Thank you!
Beta Was this translation helpful? Give feedback.
All reactions