Closed frederikhors closed 2 years ago
I would like a method like: getKeyStartsWith(key: string)
to find for example keys like: /players?page=1
.
And then I can search values for the playerId
I need in detail page.
What do you think?
It works. But.
As I said I'm using it for a "classic" list/detail and here what happens:
/players
list page/players
key/players/1
detail pageget("/players")
to populate my initialData
to speed up UX/players
to /players/1
the key /players
is refetched in background hence the get("/players")
does not return data, only a Promise, useless in this caseBut if I need a Promise
I can use getOrWait()
instead.
So I think we should not "change" the cache during refetching because we need to get()
something even if is stale.
What do you think?
I think we need a method like getStartingWith(key: string)
.
Why not just use the mutate to populate other keys or just use useSWR with revalidation set to false? There is a bunch of options you can pass to it!
Why not just use the mutate to populate other keys
I cannot, because I'm checking for data already in cache during new fetch...
or just use useSWR with revalidation set to false
The players list is refetching because I'm using a variable, and it can depends on other usecases.
Cannot be this the solution.
What you are trying to achieve is probably not possible.
To achieve such behaviour you could either: a) parse your one object on the first fetch and populate the cache with individual objects b) use graphql which has such features because of fragments and strong typing on both ends (f.e. with urql's graphcache).
But there is no way to get this for free. You have to type and/or parse your data at some point.
It's possible.
I'm getting the players
object which is like this:
{ players: [{id: "1", name: "Name"}, ...and others] }
and with a .find()
I can find my player/1
.
It's doable right now with svelte-query.
{ players: [{id: "1", name: "Name"}, ...and others] }
Just find the player with id = 1 and put it in the cache:
mutate('player/1', {id: "1", name: "Name"})
Just find the player with id = 1
This is what I'm asking you!
If I use get()
and the query is re-fetching I cannot find players (already fetched before) because I get a promise!
mutate
or initialData
is not a problem!
You have to change step 4 from your list.
I populate the cache /players/${id} for each fetched player using mutate()
But I don't know if a use will need this.
I'm opening a new page and in background the previous list is refetching (for many reasons).
This is not a valid solution.
How would this be done in https://swr.vercel.app otherwise?
I don't know, But it's doable in this project, the problem is we need to swap the data for that key only when the promise is resolved, not before.
IMO.
IMHO: a) your sentences make no sense, are incomplete, plain false or simply not understandable. b) no github-repo is your personal support-forum c) "This is what I'm asking you!"? Are you nuts or simply rude? @ConsoleTVs provides a lib, developed in his freetime, free of charge, he even provides support and you dare to demand anything? Be grateful and nothing else. Period. d) I'm out. I'll no longer answer questions or similar by you.
@benbender I love you. 😄
My verdict has fallen: you are plainly arrogant. For no obvious reason. #kthxbye #block
I really don't understand your behavior, @benbender.
Did you block me simply because I told you I love you? To avoid replying and wasting your time reading a reply to a useless message you wrote.
A message that doesn't make sense: I wasn't "demanding" anything from @ConsoleTVs; and among other things, as you well know and as @ConsoleTVs can tell, I am helping and collaborating with various PR on this splendid project.
You did not understand my question and you get angry, it seems like childish behavior to me.
Grow, live and let live.
Lots of little kisses.
In the classic example of
list/detail
if I click on the single detail element I wanna check the cache (under list key) to get data forinitialData
but now there is no way to get cache right?Should we expose methods for get the cache?