]> git.ipfire.org Git - thirdparty/vuejs/pinia.git/commitdiff
fix: avoid modifying options argument
authorEduardo San Martin Morote <posva13@gmail.com>
Fri, 16 Jul 2021 15:36:49 +0000 (17:36 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Mon, 19 Jul 2021 09:52:25 +0000 (11:52 +0200)
__tests__/actions.spec.ts
__tests__/storePlugins.spec.ts
src/devtools/plugin.ts
src/store.ts

index 70f74f02fae286ed0ec6a8b0573c82b73deaa7f1..58c5bcdd08c886c840efcfdfe045edbaa43672b4 100644 (file)
@@ -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)
index de14f91f8b17881ada54e2f1fba862089b58dfcf..1c198e2a5a27d15d579d80bfde81a57eb79c4792 100644 (file)
@@ -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<Id> {
index e8ff0886c419bcd68206f10a3470c14ed5b9308f..28a1d6ddc94127637f49659026c8125d09d3d312 100644 (file)
@@ -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, {
index d3acf10dd54b2dccaa781048bfb6fcd1776a30ad..c637dc4d622d5fb377272974b971a92d6152eccc 100644 (file)
@@ -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]
         }