]> git.ipfire.org Git - thirdparty/vuejs/pinia.git/commitdiff
refactor: use assign instead of spread
authorEduardo San Martin Morote <posva13@gmail.com>
Wed, 3 Mar 2021 16:38:27 +0000 (17:38 +0100)
committerEduardo San Martin Morote <posva13@gmail.com>
Mon, 8 Mar 2021 14:50:05 +0000 (15:50 +0100)
src/devtools.ts
src/store.ts
src/utils.ts [moved from src/env.ts with 59% similarity]

index 4be13c2aa8df59aeaf9ad22c6479dbb03f2f7c4c..88e1cd507640fc75f47e1eeaa913f92fd633953a 100644 (file)
@@ -1,4 +1,5 @@
 import { DevtoolHook, StateTree, StoreWithState } from './types'
+import { assign } from './utils'
 
 const target =
   typeof window !== 'undefined'
@@ -79,10 +80,10 @@ export function useStoreDevtools(store: StoreWithState<string, StateTree>) {
     rootStore.state[store.$id] = state
     devtoolHook.emit(
       'vuex:mutation',
-      {
-        ...mutation,
-        type: `[${mutation.storeName}] ${mutation.type}`,
-      },
+      assign({},
+        mutation,
+        {type: `[${mutation.storeName}] ${mutation.type}`,
+      }),
       rootStore.state
     )
   })
index 403486a1c8cf9b0901830c53fe0cf03f5aea8eec..cd5c411af2b6a0e23f2eca884560247b4b4e19c9 100644 (file)
@@ -28,6 +28,7 @@ import {
   PiniaCustomProperties,
   piniaSymbol,
 } from './rootStore'
+import { assign } from './utils'
 
 const isClient = typeof window != 'undefined'
 
@@ -230,21 +231,21 @@ function buildStoreToUse<
   }
 
   const extensions = pinia._p.reduce(
-    (extended, extender) => ({
-      ...extended,
-      ...extender(),
-    }),
+    (extended, extender) => assign({}, extended, extender()),
     {} as PiniaCustomProperties
   )
 
-  const store: Store<Id, S, G, A> = reactive({
-    ...extensions,
-    ...partialStore,
-    // using this means no new properties can be added as state
-    ...computedFromState(pinia.state, $id),
-    ...computedGetters,
-    ...wrappedActions,
-  }) as Store<Id, S, G, A>
+  const store: Store<Id, S, G, A> = reactive(
+    assign(
+      {},
+      extensions,
+      partialStore,
+      // using this means no new properties can be added as state
+      computedFromState(pinia.state, $id),
+      computedGetters,
+      wrappedActions
+    )
+  ) as Store<Id, S, G, A>
 
   // 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
similarity index 59%
rename from src/env.ts
rename to src/utils.ts
index 53538e8576cabfa8bec593721f1b279c0c9f2f4d..a6dadca291892544e2fe810c3aa80f88c0ebcc23 100644 (file)
@@ -1 +1,3 @@
 export const IS_CLIENT = typeof window !== 'undefined'
+
+export const assign = Object.assign