Skip to content

Commit

Permalink
perf: reduce the performance cost of component changed (#139)
Browse files Browse the repository at this point in the history
  • Loading branch information
webfansplz authored Jan 3, 2024
1 parent 12bed15 commit b672137
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions packages/devtools-kit/src/core/plugins/components.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { VueAppInstance } from '@vue/devtools-schema'
import { debounce } from 'perfect-debounce'
import { setupDevToolsPlugin } from '../../api/plugin'
import { getAppRecord, getComponentId, getComponentInstance } from '../component/general'
import { devtoolsContext } from '../general/state'
Expand Down Expand Up @@ -84,6 +85,14 @@ export function registerComponentsDevTools(app: VueAppInstance) {
}
})

const debounceSendInspectorTree = debounce(() => {
api.sendInspectorTree(INSPECTOR_ID)
}, 120)

const debounceSendInspectorState = debounce(() => {
api.sendInspectorState(INSPECTOR_ID)
}, 120)

const componentAddedCleanup = hook.on.componentAdded(async (app, uid, parentUid, component) => {
if (app?._instance?.type?.devtools?.hide)
return
Expand All @@ -109,7 +118,7 @@ export function registerComponentsDevTools(app: VueAppInstance) {
if (!appRecord)
return

api.sendInspectorTree(INSPECTOR_ID)
debounceSendInspectorTree()
})

const componentUpdatedCleanup = hook.on.componentUpdated(async (app, uid, parentUid, component) => {
Expand Down Expand Up @@ -137,8 +146,8 @@ export function registerComponentsDevTools(app: VueAppInstance) {
if (!appRecord)
return

api.sendInspectorTree(INSPECTOR_ID)
api.sendInspectorState(INSPECTOR_ID)
debounceSendInspectorTree()
debounceSendInspectorState()
})
const componentRemovedCleanup = hook.on.componentRemoved(async (app, uid, parentUid, component) => {
if (app?._instance?.type?.devtools?.hide)
Expand All @@ -159,7 +168,7 @@ export function registerComponentsDevTools(app: VueAppInstance) {
}) as string
appRecord?.instanceMap.delete(id)

api.sendInspectorTree(INSPECTOR_ID)
debounceSendInspectorTree()
})
devtoolsContext.componentPluginHookBuffer = [
componentAddedCleanup,
Expand Down

0 comments on commit b672137

Please sign in to comment.