You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
But ImmortalDB.get returns a Promise, so the above line would be return await ImmortalDB.get('key').
And React's useState does not support async functions,
so a synchronousget would be very helpful
The text was updated successfully, but these errors were encountered:
Hey! The problem with a synchronous API is that not all the datastores underlying ImmortalDB offer synchronous APIs. Like IndexedDB:
Operations performed using IndexedDB are done asynchronously, so as not
to block applications. IndexedDB originally included both synchronous
and asynchronous APIs. The synchronous API was intended for use only
with Web Workers but was removed from the spec because it was unclear
whether it was needed. However, the synchronous API may be reintroduced
if there is enough demand from web developers.
If you need a synchronous API, one potential future feature for ImmortalDB would be to offer a sync API if ImmortalDB was created with only data stores that in turn all offer synchronous APIs. E.g.
const syncStores = [await SynchronousStore1(), await SynchronousStore2(), ...]
const db = new ImmortalStorage(syncStores)
db.get(key) // Synchronous.
But this 1) limits the data stores that can be used and 2) doesn't seem worth the effort nor API complication.
The better solution, to me, would be for React's useState() to support async functions. It's not just ImmortalDB; if any React user wanted to interact with a plain old IndexedDB database in useState(), async would be required, too.
Very helpful package! Thank you.
I'm using
ImmortalDB
with React to save some page state to local.I would like to init a component's state by loading locally stored state, like:
But
ImmortalDB.get
returns a Promise, so the above line would bereturn await ImmortalDB.get('key')
.And React's
useState
does not support async functions,so a synchronous
get
would be very helpfulThe text was updated successfully, but these errors were encountered: