From: Eduardo San Martin Morote Date: Thu, 31 Mar 2022 09:03:27 +0000 (+0200) Subject: fix(vue2): use toRefs in storeToRefs X-Git-Tag: @pinia/testing@0.0.11~13 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0f24ad27f16bd473e20a8671cd24877d2603cbcf;p=thirdparty%2Fvuejs%2Fpinia.git fix(vue2): use toRefs in storeToRefs Close #852 --- diff --git a/packages/pinia/src/storeToRefs.ts b/packages/pinia/src/storeToRefs.ts index d0ba5a4f..fc294d31 100644 --- a/packages/pinia/src/storeToRefs.ts +++ b/packages/pinia/src/storeToRefs.ts @@ -23,30 +23,29 @@ export function storeToRefs( ): ToRefs< StoreState & StoreGetters & PiniaCustomStateProperties> > { - if (__DEV__ && isVue2) { - console.warn( - '[Pinia]: "storeToRefs()" currently only works on Vue 3 until https://github.com/vuejs/pinia/issues/852 is fixed. Please, use "toRefs()" (from vue) instead. This will FAIL in production if not changed.' - ) + // See https://github.com/vuejs/pinia/issues/852 + // It's easier to just use toRefs() even if it includes more stuff + if (isVue2) { // @ts-expect-error: toRefs include methods and others return toRefs(store) - } - - store = toRaw(store) + } else { + store = toRaw(store) - const refs = {} as ToRefs< - StoreState & - StoreGetters & - PiniaCustomStateProperties> - > - for (const key in store) { - const value = store[key] - if (isRef(value) || isReactive(value)) { - // @ts-expect-error: the key is state or getter - refs[key] = - // --- - toRef(store, key) + const refs = {} as ToRefs< + StoreState & + StoreGetters & + PiniaCustomStateProperties> + > + for (const key in store) { + const value = store[key] + if (isRef(value) || isReactive(value)) { + // @ts-expect-error: the key is state or getter + refs[key] = + // --- + toRef(store, key) + } } - } - return refs + return refs + } }