]> git.ipfire.org Git - thirdparty/vuejs/pinia.git/commitdiff
fix: accept reactive with storeToRefs
authorEduardo San Martin Morote <posva13@gmail.com>
Fri, 19 Nov 2021 12:46:19 +0000 (13:46 +0100)
committerEduardo San Martin Morote <posva13@gmail.com>
Fri, 19 Nov 2021 12:46:19 +0000 (13:46 +0100)
Close #799

packages/pinia/__tests__/storeToRefs.spec.ts
packages/pinia/src/store.ts

index eb7e1d6def57e5b5a04e83fe51ca471d31234866..8db6e197a82b89c00974def37eb4ef5854c628ac 100644 (file)
@@ -45,7 +45,7 @@ describe('storeToRefs', () => {
     expect(d.value).toBe('e')
   })
 
-  it.skip('setup store', () => {
+  it('setup store', () => {
     const store = defineStore('a', () => {
       return {
         a: ref<null | undefined>(null),
@@ -80,8 +80,8 @@ describe('storeToRefs', () => {
     expect(r.value).toEqual({ n: 2 })
     expect(store.r).toEqual({ n: 2 })
     store.r.n++
-    expect(r.value).toEqual({ n: 2 })
-    expect(store.r).toEqual({ n: 2 })
+    expect(r.value).toEqual({ n: 3 })
+    expect(store.r).toEqual({ n: 3 })
   })
 
   it('empty getters', () => {
index b1ea24845b1e23219bfa0443261f25567462343f..45234ad2124dd0852c55e16a1af9af1ea35ee06c 100644 (file)
@@ -13,6 +13,7 @@ import {
   effectScope,
   EffectScope,
   ComputedRef,
+  toRaw,
   toRef,
   toRefs,
   Ref,
@@ -526,6 +527,9 @@ function createSetupStore<
     })
   } else {
     assign(store, setupStore)
+    // allows retrieving reactive objects with `storeToRefs()`. Must be called after assigning to the reactive object.
+    // https://github.com/posva/pinia/issues/799
+    assign(toRaw(store), setupStore)
   }
 
   // use this instead of a computed with setter to be able to create it anywhere