Skip to content

Commit

Permalink
perf(devtools): avoid multiple subscriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
posva committed May 15, 2021
1 parent 39656b6 commit ea62f1d
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/devtools/plugin.ts
Expand Up @@ -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(
Expand Down Expand Up @@ -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++

Expand Down

0 comments on commit ea62f1d

Please sign in to comment.