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

feat: mutate filter #1989

Merged
merged 22 commits into from Jun 26, 2022
Merged

feat: mutate filter #1989

merged 22 commits into from Jun 26, 2022

Conversation

huozhi
Copy link
Member

@huozhi huozhi commented May 24, 2022

Closes #1946.

Description

The global mutate API (imported directly from SWR or returned by useSWRConfig) can now accept a filter function, to match multiple keys for mutating:

await mutate(
  key => typeof key === 'string' && key.startsWith('/api/'),
  undefined, // newData | (data => newData)
  false,     // shouldRevalidate = true
)

Breaking Changes

  • This deprecates the use case of accepting a function that returns a key.
  • The Cache interface now requires a keys() method that returns all keys in the cache object, similar to the JavaScript Map instances.

Usage

(See #1946)

@codesandbox-ci
Copy link

codesandbox-ci bot commented May 24, 2022

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 dcda636:

Sandbox Source
SWR-Basic Configuration
SWR-States Configuration
SWR-Infinite Configuration
SWR-SSR Configuration

_internal/utils/mutate.ts Outdated Show resolved Hide resolved
_internal/utils/mutate.ts Outdated Show resolved Hide resolved
@huozhi huozhi marked this pull request as ready for review May 26, 2022 15:45
@huozhi huozhi marked this pull request as draft May 26, 2022 16:31
_internal/utils/mutate.ts Outdated Show resolved Hide resolved
_internal/utils/mutate.ts Outdated Show resolved Hide resolved
_internal/utils/mutate.ts Outdated Show resolved Hide resolved
@shuding shuding marked this pull request as ready for review June 26, 2022 18:02
@huozhi
Copy link
Member Author

huozhi commented Jun 26, 2022

Thank you shu for helping fixing the issues and those changes look good

image

@shuding
Copy link
Member

shuding commented Jun 26, 2022

(I think there’s still one last blocker which is to make useSWRInfinite work properly)

@shuding shuding marked this pull request as draft June 26, 2022 22:04
@shuding shuding marked this pull request as ready for review June 26, 2022 22:05
@shuding
Copy link
Member

shuding commented Jun 26, 2022

OK this is more like a general problem today, need to think deeper about it. Meanwhile this PR can be shipped!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RFC: Mutate multiple items
3 participants