Skip to content

Commit 3a2a334

Browse files
committed
fix: accept reactive with storeToRefs
Close #799
1 parent 9e45c4f commit 3a2a334

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

packages/pinia/__tests__/storeToRefs.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ describe('storeToRefs', () => {
4545
expect(d.value).toBe('e')
4646
})
4747

48-
it.skip('setup store', () => {
48+
it('setup store', () => {
4949
const store = defineStore('a', () => {
5050
return {
5151
a: ref<null | undefined>(null),
@@ -80,8 +80,8 @@ describe('storeToRefs', () => {
8080
expect(r.value).toEqual({ n: 2 })
8181
expect(store.r).toEqual({ n: 2 })
8282
store.r.n++
83-
expect(r.value).toEqual({ n: 2 })
84-
expect(store.r).toEqual({ n: 2 })
83+
expect(r.value).toEqual({ n: 3 })
84+
expect(store.r).toEqual({ n: 3 })
8585
})
8686

8787
it('empty getters', () => {

packages/pinia/src/store.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
effectScope,
1414
EffectScope,
1515
ComputedRef,
16+
toRaw,
1617
toRef,
1718
toRefs,
1819
Ref,
@@ -526,6 +527,9 @@ function createSetupStore<
526527
})
527528
} else {
528529
assign(store, setupStore)
530+
// allows retrieving reactive objects with `storeToRefs()`. Must be called after assigning to the reactive object.
531+
// https://github.com/posva/pinia/issues/799
532+
assign(toRaw(store), setupStore)
529533
}
530534

531535
// use this instead of a computed with setter to be able to create it anywhere

0 commit comments

Comments
 (0)