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

Refine createCache #1283

Merged
merged 12 commits into from
Jul 19, 2021
Merged

Refine createCache #1283

merged 12 commits into from
Jul 19, 2021

Conversation

huozhi
Copy link
Member

@huozhi huozhi commented Jul 10, 2021

Fixes #1275

Changes

  • Only need to setupOn<Event> for cache
  • Setup global listeners inside createCache
createCache(new Map(), {
  // if you want to override any event that can trigger revalidation, use following options

  // override default behavior of revalidate on focus, it will revalidate on your own `focus` event now
  setupOnFocus(focusRevalidator) {
      customEvent.on('focus', focusRevalidator)
   },

   // override default behavior of revalidate on reconnect, it will revalidate on custom network events now
   setupOnReconnect(reconnectRevalidator) {
     customEvent.on('reconnect', reconnectRevalidator)
   }
})

Fixes

  • Fix custom cache is not bound to env like focus, reconnect events on web

@huozhi huozhi requested a review from shuding as a code owner July 10, 2021 12:34
@codesandbox-ci
Copy link

codesandbox-ci bot commented Jul 10, 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 b84215b:

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

@huozhi huozhi force-pushed the fix/revalidteonfocus-cache branch from 9d56c96 to e6d1b21 Compare July 10, 2021 12:40
src/types.ts Outdated Show resolved Hide resolved
src/use-swr.ts Outdated Show resolved Hide resolved
src/use-swr.ts Outdated Show resolved Hide resolved
src/use-swr.ts Outdated Show resolved Hide resolved
src/use-swr.ts Outdated Show resolved Hide resolved
@huozhi huozhi changed the title Fix revalidateOnFocus with custom cache Refine createCache Jul 15, 2021
src/utils/web-preset.ts Outdated Show resolved Hide resolved
src/utils/web-preset.ts Outdated Show resolved Hide resolved
src/use-swr.ts Outdated Show resolved Hide resolved
@shuding
Copy link
Member

shuding commented Jul 15, 2021

I pushed a change due to one comment ☝️ , let me know what do you think!

@huozhi huozhi marked this pull request as draft July 16, 2021 07:16
@huozhi huozhi force-pushed the fix/revalidteonfocus-cache branch from 17e8792 to 2674fdc Compare July 16, 2021 07:28
@huozhi huozhi marked this pull request as ready for review July 16, 2021 07:29
@huozhi huozhi requested a review from shuding July 16, 2021 07:29
@huozhi
Copy link
Member Author

huozhi commented Jul 16, 2021

force pushed it but honored your changes @shuding
also add 2 test cases to cover the core changes

src/utils/web-preset.ts Outdated Show resolved Hide resolved
@huozhi huozhi requested a review from shuding July 18, 2021 15:46
@shuding shuding merged commit 97c49ba into master Jul 19, 2021
@shuding shuding deleted the fix/revalidteonfocus-cache branch July 19, 2021 10:47
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.

createCache with revalidateOnFocus does not work
3 participants