]> git.ipfire.org Git - thirdparty/vuejs/pinia.git/commitdiff
perf(devtools): avoid multiple subscriptions
authorEduardo San Martin Morote <posva13@gmail.com>
Sat, 15 May 2021 15:12:49 +0000 (17:12 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Sat, 15 May 2021 15:15:18 +0000 (17:15 +0200)
src/devtools/plugin.ts

index a42a7287cd286a4acfcec30830d84b588d82eb95..23e25cabde5960a94cce88a247c23878b4a0525d 100644 (file)
@@ -30,9 +30,14 @@ const MUTATIONS_LAYER_ID = 'pinia:mutations'
 const INSPECTOR_ID = 'pinia'
 
 export function addDevtools(app: App, store: Store) {
+  // TODO: we probably need to ensure the latest version of the store is kept:
+  // without effectScope, multiple stores will be created and will have a
+  // limited lifespan for getters.
+  let hasSubscribed = true
   if (!registeredStores.has(store.$id)) {
     registeredStores.set(store.$id, store)
     componentStateTypes.push('🍍 ' + store.$id)
+    hasSubscribed = true
   }
 
   setupDevtoolsPlugin(
@@ -188,6 +193,9 @@ export function addDevtools(app: App, store: Store) {
         api.sendInspectorState(INSPECTOR_ID)
       }
 
+      // avoid subscribing to mutations and actions twice
+      if (hasSubscribed) return
+
       store.$onAction(({ after, onError, name, args, store }) => {
         const groupId = runningActionId++