-
-
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
add selectInvalidatedBy
#1665
add selectInvalidatedBy
#1665
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 3075999:
|
size-limit report 📦
|
This looks good overall, I'm just trying to think about the use cases. |
Optimistic updates of paginated lists where you don't know on which page (or even which pages are in the cache) it is for example. async onQueryStarted({ id, ...patch }, { dispatch, queryFulfilled, getState }) {
for (const { endpointName, originalArgs } of api.selectInvalidatedBy(getState(), { type: "Post", id})) {
if ( endpointName !== 'getPosts') continue;
dispatch(
api.util.updateQueryData(endpoint, originalArgs, (draft) => {
// find in list & update
})
)
},
}, |
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.
Looks 💪. My only thought is that we could potentially update the invalidation test matrix for this case:
// *****************************
// test multiple values in array
// *****************************
[['apple', { type: 'banana' }, 'tomato'], ['apple'], true],
This is covered in the block above with the // string and type only behave identical
section though, so we could assume this is always safe? 🤷
Just push an extra use case if you see the need for it :) |
This should be very useful for people that do a lot of manual optimistic updated.