square / svelte-store

528 stars 36 forks source link

IndexedDB? #64

Closed frederikhors closed 1 year ago

frederikhors commented 1 year ago

Amazing project, congratulations!

Is there a way to persist to IndexedDB?

Akolyte01 commented 1 year ago

Hey there! Thank you. There is not currently any support for that and I don't think I would want to have a dependency explicitly built into the package. However what might work is to allow persisted stores to be optionally configured to add custom storage types.

i.e. something like this....

createStorageType('INDEXED_DB', { getStorageItem:  // custom get function, setStorageItem: // custom set function, removeStorageItem: // custom remove function});

const somePersistedData = persisted(
  'some initial value',
  'SOME_KEY',
  { storageType: 'INDEXED_DB' }
);

Does that sound like it would work?

frederikhors commented 1 year ago

Yeah. Something like that.

I would like to have something like tanstack/query with persistence in browser.

tanstack/query currently does not support Svelte persistence: https://github.com/TanStack/query/discussions/5463

Akolyte01 commented 1 year ago

new feature should be out and live on version 1.0.16 https://github.com/square/svelte-store/commit/2fcd8f912304e345f8937044f7bfba35903339d9