Skip to content

Commit

Permalink
fix: use assign to set $state
Browse files Browse the repository at this point in the history
Fix #682
  • Loading branch information
posva committed Sep 29, 2021
1 parent a741adc commit f3a732f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
7 changes: 7 additions & 0 deletions packages/pinia/__tests__/store.spec.ts
Expand Up @@ -137,6 +137,11 @@ describe('Store', () => {

it('can replace its state', () => {
const store = useStore()
const spy = jest.fn()
watch(() => store.a, spy, { flush: 'sync' })
expect(store.a).toBe(true)

expect(spy).toHaveBeenCalledTimes(0)
// TODO: remove once plugin state achieve generics
// @ts-expect-error
store.$state = {
Expand All @@ -148,6 +153,8 @@ describe('Store', () => {
},
},
}
expect(spy).toHaveBeenCalledTimes(1)

expect(store.$state).toEqual({
a: false,
nested: {
Expand Down
4 changes: 3 additions & 1 deletion packages/pinia/src/store.ts
Expand Up @@ -532,7 +532,9 @@ function createSetupStore<
if (__DEV__ && hot) {
throw new Error('cannot set hotState')
}
pinia.state.value[$id] = state
$patch(($state) => {
assign($state, state)
})
},
})

Expand Down

0 comments on commit f3a732f

Please sign in to comment.