Comments (20)
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?
from sswr.
You've got:
https://github.com/ConsoleTVs/sswr/blob/master/src/index.ts#L105
and
https://github.com/ConsoleTVs/sswr/blob/master/src/index.ts#L115
from sswr.
It works. But.
As I said I'm using it for a "classic" list/detail and here what happens:
- I'm on the
/players
list page - I have fetched data with
/players
key - I move on the
/players/1
detail page - On detail page I use
get("/players")
to populate myinitialData
to speed up UX - BUT during this navigation from
/players
to/players/1
the key/players
is refetched in background hence theget("/players")
does not return data, only a Promise, useless in this case
But 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?
from sswr.
I think we need a method like getStartingWith(key: string)
.
from sswr.
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!
from sswr.
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.
from sswr.
What you are trying to achieve is probably not possible.
- You are fetching the endpoint for /players and retrieve one(!) object (most likely parsed from a json-string)
- You are navigating to /players/1 and want the cache to know which part of the data in the cache belongs to player with id 1. Problem is that this information isn't retrieved by the cache.
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.
from sswr.
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
.
from sswr.
It's doable right now with svelte-query.
from sswr.
{ 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"})
from sswr.
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!
from sswr.
mutate
or initialData
is not a problem!
from sswr.
You have to change step 4 from your list.
- I'm on the /players list page
- I have fetched data with /players key
- I populate the cache /players/${id} for each fetched player using mutate()
- I move on the /players/1 detail page
- UX will first show the stale / cached data while it re-validates it in the background.
from sswr.
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.
from sswr.
How would this be done in https://swr.vercel.app otherwise?
from sswr.
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.
from sswr.
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.
from sswr.
@benbender I love you. 😄
from sswr.
My verdict has fallen: you are plainly arrogant. For no obvious reason. #kthxbye #block
from sswr.
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.
from sswr.
Related Issues (20)
- Dependent fetching just doesn't work? HOT 12
- Support synchronous `fetcher` function HOT 3
- `fetcher` is sometimes ignored and it uses the default `fetch` HOT 1
- If `fetcher` returns `null` the revalidation is ignored HOT 1
- make revalidate() fires immediately? HOT 4
- Add `isValidating` prop HOT 1
- revalidateOnMount missing? HOT 2
- Server side rendering SvelteKit example does not work
- SvelteKit - Named export 'SWR' not found HOT 3
- [HELP] Error: Function called outside component initialization
- Add option for polling interval
- Posible vite4 incompatibility HOT 2
- Multiple SWRs in one component keep resetting each other
- Dependent fetching doesn't revalidate when changing to an already cached value
- Svelte 4 support HOT 2
- Difference to @tanstack/svelte-query HOT 1
- Documentation typo: Global configuration options HOT 1
- SSWR no longer updating with longer `dedupingInterval`
- Is there a changelog?
- Quality control & maintenance of SSWR HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sswr.