-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Keep track updatedAt
as part of the SWR state
#1708
base: main
Are you sure you want to change the base?
Conversation
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit be0c42e:
|
Thank you @icyJoseph — the implementation looks great! One more thing I think we should include in the test is reflecting the And also, I'd like to hear your idea about the name "updatedAt" here. Should we call it "fetchedAt"? Simply because I've been thinking about this "updatedAt" name for a while and it feels that the |
Right, if we have two or more hooks looking at the same key,
I see, mutate calls can take many shapes, from a simple call to fetch fresh data, to a controlled call where we are in total control of the new data. I do agree that Here, |
It's a bit tricky, since the After some research, I think we should change the structure of the cache into "key → { data, error, isValidating, ... }". Currently it is "data_key → data", "error_key → error", ... which is not very extendable. |
I agree with your last point there. Just as an update, over the holidays I wrote a test to check that other hooks consuming For better or worse, the test failed, so I've been making some changes to turn it green. While I am at, I've come to believe that either |
Now I am back from my break. I see I've been making an error on my tests. Mostly the call to mutate, and expecting that calls to it should reflect similar
In this case, we are talking purely about calls to I'll rewrite the two tests that use |
@shuding how do you feel about the PR now? I think we just need to decide a name for the prop:
Other names could be |
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.
I’m back too and thank you @icyJoseph, the implementation now looks excellent to me as well as those tests.
Regarding the name I think fetchedAt
is still better. Or, I’d like to give it a try to also include the update time of mutations, and keep the name updatedAt
(really want to make it polished before releasing as a stable API).
To make that happen, I’ll come up with a PR to change the cache structure to keep all states by one single key.
Does the plan sound good to you?
@shuding Alright, then should we wait on your PR first, and then adapt this branch to that? |
What happened to this PR? I was thinking of writing some similar functionality myself. |
sad that it hasn't been implemented. |
Seeding work to keep track of the
updatedAt
time. #1703At the top of my head I can think of a few things to do: