From a3709b3ae94490eb6f5ded66ecda313fec4d146e Mon Sep 17 00:00:00 2001 From: Yixuan Xu Date: Sun, 9 May 2021 18:48:01 +0800 Subject: [PATCH 1/2] fix global mutate generic (#1159) fix #1155 --- src/types.ts | 19 ++++++++++++++----- src/use-swr.ts | 4 ++-- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/types.ts b/src/types.ts index c49301f3c..072df0772 100644 --- a/src/types.ts +++ b/src/types.ts @@ -90,11 +90,20 @@ export type Mutator = ( shouldRevalidate?: boolean ) => Promise -export type ScopedMutator = ( - key: Key, - data?: Data | Promise | MutatorCallback, - shouldRevalidate?: boolean -) => Promise +export interface ScopedMutator { + /** This is used for bound mutator */ + ( + key: Key, + data?: Data | Promise | MutatorCallback, + shouldRevalidate?: boolean + ): Promise + /** This is used for global mutator */ + ( + key: Key, + data?: T | Promise | MutatorCallback, + shouldRevalidate?: boolean + ): Promise +} export type KeyedMutator = ( data?: Data | Promise | MutatorCallback, diff --git a/src/use-swr.ts b/src/use-swr.ts index 35fd4a68e..70ba71fa3 100644 --- a/src/use-swr.ts +++ b/src/use-swr.ts @@ -700,7 +700,8 @@ Object.defineProperty(SWRConfig, 'default', { export const mutate = internalMutate.bind( null, defaultConfig.cache -) as ScopedMutator +) as ScopedMutator + export function createCache( provider: Cache ): { @@ -713,5 +714,4 @@ export function createCache( mutate: internalMutate.bind(null, cache) as ScopedMutator } } - export default useSWR From 05962874576051efee885ebc57f4d1727c3e8d1c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 11 May 2021 15:12:43 +0800 Subject: [PATCH 2/2] build(deps): bump hosted-git-info from 2.8.5 to 2.8.9 (#1164) --- yarn.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/yarn.lock b/yarn.lock index 67b3489b9..83a97150e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3429,9 +3429,9 @@ has@^1.0.3: function-bind "^1.1.1" hosted-git-info@^2.1.4: - version "2.8.5" - resolved "https://registry.yarnpkg.com/hosted-git-info/-/hosted-git-info-2.8.5.tgz#759cfcf2c4d156ade59b0b2dfabddc42a6b9c70c" - integrity sha512-kssjab8CvdXfcXMXVcvsXum4Hwdq9XGtRD3TteMEvEbq0LXyiNQr6AprqKqfeaDXze7SxWvRxdpwE6ku7ikLkg== + version "2.8.9" + resolved "https://registry.yarnpkg.com/hosted-git-info/-/hosted-git-info-2.8.9.tgz#dffc0bf9a21c02209090f2aa69429e1414daf3f9" + integrity sha512-mxIDAb9Lsm6DoOJ7xH+5+X4y1LU/4Hi50L9C5sIswK3JzULS4bwk1FvjdBgvYR4bzT4tuUQiC15FE2f5HbLvYw== html-encoding-sniffer@^1.0.2: version "1.0.2"