]> git.ipfire.org Git - thirdparty/vuejs/pinia.git/commitdiff
fix: correctly set the store properties in Vue 2
authorEduardo San Martin Morote <posva13@gmail.com>
Sun, 5 Sep 2021 18:18:08 +0000 (20:18 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Sun, 5 Sep 2021 18:18:08 +0000 (20:18 +0200)
Fix #657

packages/pinia/src/store.ts

index 66cd9eb5e5ee1a430c11893abc2dcfff0b504af5..b77f1f2ff03a0be242cc7a84c34f9056373a1153 100644 (file)
@@ -491,7 +491,18 @@ function createSetupStore<
   }
 
   // add the state, getters, and action properties
-  assign(store, setupStore)
+  if (isVue2) {
+    Object.keys(setupStore).forEach((key) => {
+      set(
+        store,
+        key,
+        // @ts-expect-error: valid key indexing
+        setupStore[key]
+      )
+    })
+  } else {
+    assign(store, setupStore)
+  }
 
   // use this instead of a computed with setter to be able to create it anywhere
   // without linking the computed lifespan to wherever the store is first