From: Eduardo San Martin Morote Date: Fri, 16 Jul 2021 15:36:49 +0000 (+0200) Subject: fix: avoid modifying options argument X-Git-Tag: v2.0.0-rc.0~60 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=59ac9b962778f730ade9c2a8b1a575922957d907;p=thirdparty%2Fvuejs%2Fpinia.git fix: avoid modifying options argument --- diff --git a/__tests__/actions.spec.ts b/__tests__/actions.spec.ts index 70f74f02..58c5bcdd 100644 --- a/__tests__/actions.spec.ts +++ b/__tests__/actions.spec.ts @@ -110,6 +110,13 @@ describe('Actions', () => { }) it('can force the pinia', () => { + // setup other pinias to force possible override effects on the options effect + const pinia11 = createPinia() + // const pinia22 = createPinia() + setActivePinia(pinia11) + useA() + setActivePinia(undefined) + const pinia1 = createPinia() const pinia2 = createPinia() const aStore = useA(pinia1) diff --git a/__tests__/storePlugins.spec.ts b/__tests__/storePlugins.spec.ts index de14f91f..1c198e2a 100644 --- a/__tests__/storePlugins.spec.ts +++ b/__tests__/storePlugins.spec.ts @@ -1,6 +1,6 @@ import { createPinia, defineSetupStore, defineStore } from '../src' import { mount } from '@vue/test-utils' -import { App, computed, Ref, ref, toRef } from 'vue' +import { App, computed, ref, toRef } from 'vue' declare module '../src' { export interface PiniaCustomProperties { diff --git a/src/devtools/plugin.ts b/src/devtools/plugin.ts index e8ff0886..28a1d6dd 100644 --- a/src/devtools/plugin.ts +++ b/src/devtools/plugin.ts @@ -1,6 +1,6 @@ import { setupDevtoolsPlugin, TimelineEvent } from '@vue/devtools-api' import { App, ComponentPublicInstance, toRaw } from 'vue' -import { Pinia, PiniaPluginContext, setActivePinia } from '../rootStore' +import { Pinia, PiniaPluginContext } from '../rootStore' import { Store, GettersTree, @@ -382,7 +382,7 @@ function patchActionForGrouping(store: Store, actionNames: string[]) { for (const actionName in actions) { // @ts-expect-error store[actionName] = function () { - setActivePinia(store._p) + // setActivePinia(store._p) // the running action id is incremented in a before action hook const _actionId = runningActionId const trackedStore = new Proxy(store, { diff --git a/src/store.ts b/src/store.ts index d3acf10d..c637dc4d 100644 --- a/src/store.ts +++ b/src/store.ts @@ -398,7 +398,7 @@ function createSetupStore< // list actions so they can be used in plugins // @ts-expect-error - optionsForPlugin.actions[key] = setupStore[key] // TODO: check this change from `prop` is correct + optionsForPlugin.actions[key] = prop } else if (__DEV__) { // add getters for devtools if (isComputed(prop)) { @@ -508,11 +508,8 @@ function createSetupStore< } // remove deleted getters - console.log('remove', store._hmrPayload) Object.keys(store._hmrPayload.getters).forEach((key) => { - console.log('checking for', key) if (!(key in newStore._hmrPayload.getters)) { - console.log('deleting') // @ts-expect-error delete store[key] } @@ -520,9 +517,7 @@ function createSetupStore< // remove old actions Object.keys(store._hmrPayload.actions).forEach((key) => { - console.log('checking for', key) if (!(key in newStore._hmrPayload.actions)) { - console.log('deleting') // @ts-expect-error delete store[key] }