Skip to content

Updating a cache entry without knowing the original params that generated it #4837

Discussion options

You must be logged in to vote

Here's a simplified version of the function I'm using to update the cache, since the precise mutation will depend on which model I'm dealing with and the operation in question:

function stateMutation(newState: ModelState): TypedMutationOnQueryStarted<Model, number, EmptyBaseQuery> {
  return async (id: number, api) => {
    const patchResults: { undo: () => void }[] = [];
    const flatArgs = modelApi.util.selectCachedArgsForQuery(api.getState(), 'models');
    flatArgs.forEach(p => {
      patchResults.push(
        api.dispatch(
          modelApi.util.updateQueryData('models', p, draft => {
            const d = draft.find(m => m.id === id);
            if (d) {
              d.state = n…

Replies: 2 comments 5 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
5 replies
@uraniumanchor
Comment options

@phryneas
Comment options

@markerikson
Comment options

@uraniumanchor
Comment options

Answer selected by uraniumanchor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants