From: Eduardo San Martin Morote Date: Sat, 15 May 2021 15:12:49 +0000 (+0200) Subject: perf(devtools): avoid multiple subscriptions X-Git-Tag: v2.0.0-alpha.17~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ea62f1db8d82224ea0226fa5ec90da410ff31bda;p=thirdparty%2Fvuejs%2Fpinia.git perf(devtools): avoid multiple subscriptions --- 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++