Skip to content
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

Merged
merged 3 commits into from
Oct 29, 2021
Merged

add selectInvalidatedBy #1665

merged 3 commits into from
Oct 29, 2021

Conversation

phryneas
Copy link
Member

This should be very useful for people that do a lot of manual optimistic updated.

@codesandbox-ci
Copy link

codesandbox-ci bot commented Oct 28, 2021

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:

Sandbox Source
Vanilla Configuration
Vanilla Typescript Configuration
rsk-github-issues-example Configuration

@github-actions
Copy link

github-actions bot commented Oct 28, 2021

size-limit report 📦

Path Size
1. entry point: @reduxjs/toolkit (cjs.production.min.js) 12.28 KB (0%)
1. entry point: @reduxjs/toolkit (esm.js) 10.27 KB (0%)
1. entry point: @reduxjs/toolkit/query (cjs.production.min.js) 21.93 KB (+0.44% 🔺)
1. entry point: @reduxjs/toolkit/query (esm.js) 18.23 KB (+0.33% 🔺)
1. entry point: @reduxjs/toolkit/query/react (cjs.production.min.js) 24.06 KB (+0.45% 🔺)
1. entry point: @reduxjs/toolkit/query/react (esm.js) 20.91 KB (+0.3% 🔺)
2. entry point: @reduxjs/toolkit (without dependencies) (cjs.production.min.js) 5.6 KB (0%)
2. entry point: @reduxjs/toolkit (without dependencies) (esm.js) 5.58 KB (0%)
2. entry point: @reduxjs/toolkit/query (without dependencies) (cjs.production.min.js) 9.99 KB (+0.68% 🔺)
2. entry point: @reduxjs/toolkit/query (without dependencies) (esm.js) 10.41 KB (+0.56% 🔺)
2. entry point: @reduxjs/toolkit/query/react (without dependencies) (cjs.production.min.js) 2.65 KB (0%)
2. entry point: @reduxjs/toolkit/query/react (without dependencies) (esm.js) 2.49 KB (0%)
3. createSlice (esm.js) 5.16 KB (0%)
3. createEntityAdapter (esm.js) 5.83 KB (0%)
3. configureStore (esm.js) 5.83 KB (0%)
3. createApi (esm.js) 16.49 KB (+0.42% 🔺)
3. createApi (react) (esm.js) 19.19 KB (+0.76% 🔺)
3. fetchBaseQuery (esm.js) 11.03 KB (0%)
3. setupListeners (esm.js) 9.85 KB (0%)
3. ApiProvider (esm.js) 18.03 KB (+0.8% 🔺)

@msutkowski
Copy link
Member

This looks good overall, I'm just trying to think about the use cases.

@phryneas
Copy link
Member Author

phryneas commented Oct 29, 2021

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
         })
       )
     }, 
   },

Copy link
Member

@msutkowski msutkowski left a 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? 🤷

@phryneas
Copy link
Member Author

Just push an extra use case if you see the need for it :)

@phryneas phryneas merged commit 5e36d3a into v1.7.0-integration Oct 29, 2021
@aryaemami59 aryaemami59 deleted the selectInvalidatedBy branch January 3, 2025 07:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Status: Implemented
Development

Successfully merging this pull request may close these issues.

2 participants