From ea62f1db8d82224ea0226fa5ec90da410ff31bda Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Sat, 15 May 2021 17:12:49 +0200 Subject: [PATCH] perf(devtools): avoid multiple subscriptions --- src/devtools/plugin.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/devtools/plugin.ts b/src/devtools/plugin.ts index a42a7287..23e25cab 100644 --- a/src/devtools/plugin.ts +++ b/src/devtools/plugin.ts @@ -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++ -- 2.47.2