-
Notifications
You must be signed in to change notification settings - Fork 13
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🥳🥳🥳
src/cacheExchange.ts
Outdated
let hydration: void | Promise<void>; | ||
if (opts.storage) { | ||
hydration = opts.storage.read().then(data => { | ||
store.hydrateData(data, (opts as any).storage); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What’s going on here with any
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typescript being weird.... It's saying .storage
is possibly undefined....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems to be because storage
isn’t reassigned. Maybe we can try opts.storage!
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works.... opts!.storage!
EDIT: moving to a var works better
Due to changing a lot of internals I found that making this implementation again gave profit, it's smaller 🎉
This PR adds the ability to supply two async functions to the cache, these will function as an adapter for the persistence layer of your choice.
--> will for instance write to an indexedDb and read from it, first time you start the cache it will buffer every incoming operation until the store has been hydrated by the data from your persistence layer.
During gc we perform
set(key, undefined)
on garbage collected fields/links to avoid our offline storage from heaping up.This is a first-step to a fully offline-compatible cache