@@ -20,41 +20,60 @@ export class DevToolsV6PluginAPI {
2020 return {
2121 // component inspector
2222 visitComponentTree : ( handler : DevToolsV6PluginAPIHooks [ DevToolsV6PluginAPIHookKeys . VISIT_COMPONENT_TREE ] ) => {
23- this . hooks . hook ( DevToolsV6PluginAPIHookKeys . VISIT_COMPONENT_TREE , handler )
23+ this . addHook ( DevToolsV6PluginAPIHookKeys . VISIT_COMPONENT_TREE , handler )
2424 } ,
2525 inspectComponent : ( handler : DevToolsV6PluginAPIHooks [ DevToolsV6PluginAPIHookKeys . INSPECT_COMPONENT ] ) => {
26- this . hooks . hook ( DevToolsV6PluginAPIHookKeys . INSPECT_COMPONENT , handler )
26+ this . addHook ( DevToolsV6PluginAPIHookKeys . INSPECT_COMPONENT , handler )
2727 } ,
2828 editComponentState : ( handler : DevToolsV6PluginAPIHooks [ DevToolsV6PluginAPIHookKeys . EDIT_COMPONENT_STATE ] ) => {
29- this . hooks . hook ( DevToolsV6PluginAPIHookKeys . EDIT_COMPONENT_STATE , handler )
29+ this . addHook ( DevToolsV6PluginAPIHookKeys . EDIT_COMPONENT_STATE , handler )
3030 } ,
3131
3232 // custom inspector
3333 getInspectorTree : ( handler : DevToolsV6PluginAPIHooks [ DevToolsV6PluginAPIHookKeys . GET_INSPECTOR_TREE ] ) => {
34- this . hooks . hook ( DevToolsV6PluginAPIHookKeys . GET_INSPECTOR_TREE , handler )
34+ this . addHook ( DevToolsV6PluginAPIHookKeys . GET_INSPECTOR_TREE , handler )
3535 } ,
3636 getInspectorState : ( handler : DevToolsV6PluginAPIHooks [ DevToolsV6PluginAPIHookKeys . GET_INSPECTOR_STATE ] ) => {
37- this . hooks . hook ( DevToolsV6PluginAPIHookKeys . GET_INSPECTOR_STATE , handler )
37+ this . addHook ( DevToolsV6PluginAPIHookKeys . GET_INSPECTOR_STATE , handler )
3838 } ,
3939 editInspectorState : ( handler : DevToolsV6PluginAPIHooks [ DevToolsV6PluginAPIHookKeys . EDIT_INSPECTOR_STATE ] ) => {
40- this . hooks . hook ( DevToolsV6PluginAPIHookKeys . EDIT_INSPECTOR_STATE , handler )
40+ this . addHook ( DevToolsV6PluginAPIHookKeys . EDIT_INSPECTOR_STATE , handler )
4141 } ,
4242
4343 // timeline
4444 inspectTimelineEvent : ( handler : DevToolsV6PluginAPIHooks [ DevToolsV6PluginAPIHookKeys . INSPECT_TIMELINE_EVENT ] ) => {
45- this . hooks . hook ( DevToolsV6PluginAPIHookKeys . INSPECT_TIMELINE_EVENT , handler )
45+ this . addHook ( DevToolsV6PluginAPIHookKeys . INSPECT_TIMELINE_EVENT , handler )
4646 } ,
4747 timelineCleared : ( handler : DevToolsV6PluginAPIHooks [ DevToolsV6PluginAPIHookKeys . TIMELINE_CLEARED ] ) => {
48- this . hooks . hook ( DevToolsV6PluginAPIHookKeys . TIMELINE_CLEARED , handler )
48+ this . addHook ( DevToolsV6PluginAPIHookKeys . TIMELINE_CLEARED , handler )
4949 } ,
5050
5151 // settings
5252 setPluginSettings : ( handler : DevToolsV6PluginAPIHooks [ DevToolsV6PluginAPIHookKeys . SET_PLUGIN_SETTINGS ] ) => {
53- this . hooks . hook ( DevToolsV6PluginAPIHookKeys . SET_PLUGIN_SETTINGS , handler )
53+ this . addHook ( DevToolsV6PluginAPIHookKeys . SET_PLUGIN_SETTINGS , handler )
5454 } ,
5555 }
5656 }
5757
58+ private addHook < H extends DevToolsV6PluginAPIHookKeys > ( hook : H , handler : DevToolsV6PluginAPIHooks [ H ] ) {
59+ const wrapper : any = ( ...args : [ any ] ) => {
60+ const payload = args [ 0 ]
61+ const { app, id, disableAppScope, disablePluginScope } = this . plugin . descriptor
62+
63+ if ( ! disableAppScope && payload . app != null && app !== payload . app ) {
64+ return
65+ }
66+
67+ if ( ! disablePluginScope && payload . pluginId != null && id !== payload . pluginId ) {
68+ return
69+ }
70+
71+ return handler ( ...args )
72+ }
73+
74+ this . hooks . hook ( hook , wrapper )
75+ }
76+
5877 // component inspector
5978 notifyComponentUpdate ( instance ?: ComponentInstance ) {
6079 if ( devtoolsState . highPerfModeEnabled ) {
0 commit comments