Closed axelboc closed 2 years ago
Interesting.
We have preloaded
, but do you want to set an entry after creating the store?
Yeah, precisely š
Could also be a seed()
method, but I thought prefetch
could already do the job easily.
I would think adding a new method to the store, but I wonder about naming. preload
doesn't sound super correct.
No, it's slightly different from prefetch
.
seed
sounds you can only set just once, but we could call it as many times as we want, right?
Yeah, I'd need to either call it inside forEach
, or pass an array of key/value entries.
What about store.cache()
? It has the merit of being explicit: we cache something into the store. š
That sounds vague to me. It's confusing in the library code too. How about store.preset()
?
Yeah, sure!
Please try this. https://ci.codesandbox.io/status/dai-shi/react-suspense-fetch/pr/48 Find "Local Install Instructions" āļø
Works like a charm, thanks a lot! āØ
I'm using a store to fetch entities organised in a tree structure. Each entity is identified by a path and can either be, let's say a folder or a file (but I don't know which one in advance).
To save network requests, when I fetch a folder, the response already includes the files it contains. What I'd like to do is to store those files in the store's internal cache against their respective paths, so that if they are ever requested directly, they do not get fetched again.
Right now, I'm achieving this behaviour by wrapping the fetch function I'm passing to the store and maintaining my own child cache:
This code could be simplified a lot if I had a way to add entries to the store's internal cache. My initial thought was that
store.prefetch()
could perhaps receive a resolved value as second argument. š¤·