]> git.ipfire.org Git - thirdparty/vuejs/pinia.git/commitdiff
fix: use assign to set $state
authorEduardo San Martin Morote <posva13@gmail.com>
Wed, 29 Sep 2021 09:34:04 +0000 (11:34 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Wed, 29 Sep 2021 09:34:04 +0000 (11:34 +0200)
Fix #682

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

index 34c89e489583a51fc7c8aa0f6e1d5887926bbcc6..825926887e54e171e7604b3641cb51a8aa07e28b 100644 (file)
@@ -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 = {
@@ -148,6 +153,8 @@ describe('Store', () => {
         },
       },
     }
+    expect(spy).toHaveBeenCalledTimes(1)
+
     expect(store.$state).toEqual({
       a: false,
       nested: {
index 06f7cc6e638e10e1b081e5cfcd3b32b505614528..1082d91bfaf226a9c0d017238a4835569a9918f6 100644 (file)
@@ -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)
+      })
     },
   })