From: Eduardo San Martin Morote Date: Wed, 3 Mar 2021 16:38:27 +0000 (+0100) Subject: refactor: use assign instead of spread X-Git-Tag: v0.2.0~23 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7f32baf35c00a7a81663df6f376e52fe1ad542ad;p=thirdparty%2Fvuejs%2Fpinia.git refactor: use assign instead of spread --- diff --git a/src/devtools.ts b/src/devtools.ts index 4be13c2a..88e1cd50 100644 --- a/src/devtools.ts +++ b/src/devtools.ts @@ -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) { rootStore.state[store.$id] = state devtoolHook.emit( 'vuex:mutation', - { - ...mutation, - type: `[${mutation.storeName}] ${mutation.type}`, - }, + assign({}, + mutation, + {type: `[${mutation.storeName}] ${mutation.type}`, + }), rootStore.state ) }) diff --git a/src/store.ts b/src/store.ts index 403486a1..cd5c411a 100644 --- a/src/store.ts +++ b/src/store.ts @@ -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 = reactive({ - ...extensions, - ...partialStore, - // using this means no new properties can be added as state - ...computedFromState(pinia.state, $id), - ...computedGetters, - ...wrappedActions, - }) as Store + const store: Store = reactive( + assign( + {}, + extensions, + partialStore, + // using this means no new properties can be added as state + computedFromState(pinia.state, $id), + computedGetters, + wrappedActions + ) + ) as Store // 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 diff --git a/src/env.ts b/src/utils.ts similarity index 59% rename from src/env.ts rename to src/utils.ts index 53538e85..a6dadca2 100644 --- a/src/env.ts +++ b/src/utils.ts @@ -1 +1,3 @@ export const IS_CLIENT = typeof window !== 'undefined' + +export const assign = Object.assign