Skip to content

Commit

Permalink
fix: accept reactive with storeToRefs
Browse files Browse the repository at this point in the history
Close #799
  • Loading branch information
posva committed Nov 19, 2021
1 parent 9e45c4f commit 3a2a334
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 3 additions & 3 deletions packages/pinia/__tests__/storeToRefs.spec.ts
Expand Up @@ -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),
Expand Down Expand Up @@ -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', () => {
Expand Down
4 changes: 4 additions & 0 deletions packages/pinia/src/store.ts
Expand Up @@ -13,6 +13,7 @@ import {
effectScope,
EffectScope,
ComputedRef,
toRaw,
toRef,
toRefs,
Ref,
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3a2a334

Please sign in to comment.