@@ -3,10 +3,10 @@ import {
33 hasPluginPermission ,
44 HookEvents ,
55 PluginPermission ,
6- set ,
76 getPluginDefaultSettings ,
87 getPluginSettings ,
9- setPluginSettings
8+ setPluginSettings ,
9+ StateEditor
1010} from '@vue-devtools/shared-utils'
1111import {
1212 Hooks ,
@@ -25,17 +25,22 @@ import {
2525import { DevtoolsHookable } from './hooks'
2626import { BackendContext } from './backend-context'
2727import { Plugin } from './plugin'
28+ import { DevtoolsBackend } from './backend'
29+ import { AppRecord } from './app-record'
2830
2931let backendOn : DevtoolsHookable
3032const pluginOn : DevtoolsHookable [ ] = [ ]
3133
3234export class DevtoolsApi {
3335 bridge : Bridge
3436 ctx : BackendContext
37+ backend : DevtoolsBackend
38+ stateEditor : StateEditor = new StateEditor ( )
3539
36- constructor ( bridge : Bridge , ctx : BackendContext ) {
37- this . bridge = bridge
40+ constructor ( backend : DevtoolsBackend , ctx : BackendContext ) {
41+ this . backend = backend
3842 this . ctx = ctx
43+ this . bridge = ctx . bridge
3944 if ( ! backendOn ) { backendOn = new DevtoolsHookable ( ctx ) }
4045 }
4146
@@ -171,7 +176,7 @@ export class DevtoolsApi {
171176 path : arrayPath ,
172177 type,
173178 state,
174- set : ( object , path = arrayPath , value = state . value , cb ?) => set ( object , path , value , cb || createDefaultSetCallback ( state ) )
179+ set : ( object , path = arrayPath , value = state . value , cb ?) => this . stateEditor . set ( object , path , value , cb || this . stateEditor . createDefaultSetCallback ( state ) )
175180 } )
176181 return payload . componentInstance
177182 }
@@ -240,37 +245,26 @@ export class DevtoolsApi {
240245 path : arrayPath ,
241246 type,
242247 state,
243- set : ( object , path = arrayPath , value = state . value , cb ?) => set ( object , path , value , cb || createDefaultSetCallback ( state ) )
248+ set : ( object , path = arrayPath , value = state . value , cb ?) => this . stateEditor . set ( object , path , value , cb || this . stateEditor . createDefaultSetCallback ( state ) )
244249 } )
245250 }
246251}
247252
248- function createDefaultSetCallback ( state : EditStatePayload ) {
249- return ( obj , field , value ) => {
250- if ( state . remove || state . newKey ) {
251- if ( Array . isArray ( obj ) ) {
252- obj . splice ( field , 1 )
253- } else {
254- delete obj [ field ]
255- }
256- }
257- if ( ! state . remove ) {
258- obj [ state . newKey || field ] = value
259- }
260- }
261- }
262-
263253export class DevtoolsPluginApiInstance < TSettings = any > implements DevtoolsPluginApi < TSettings > {
264254 bridge : Bridge
265255 ctx : BackendContext
266256 plugin : Plugin
257+ appRecord : AppRecord
258+ backendApi : DevtoolsApi
267259 on : DevtoolsHookable
268260 private defaultSettings : TSettings
269261
270- constructor ( plugin : Plugin , ctx : BackendContext ) {
262+ constructor ( plugin : Plugin , appRecord : AppRecord , ctx : BackendContext ) {
271263 this . bridge = ctx . bridge
272264 this . ctx = ctx
273265 this . plugin = plugin
266+ this . appRecord = appRecord
267+ this . backendApi = appRecord . backend . api
274268 this . defaultSettings = getPluginDefaultSettings ( plugin . descriptor . settings )
275269 this . on = new DevtoolsHookable ( ctx , plugin )
276270 pluginOn . push ( this . on )
@@ -282,7 +276,7 @@ export class DevtoolsPluginApiInstance<TSettings = any> implements DevtoolsPlugi
282276 if ( ! this . enabled || ! this . hasPermission ( PluginPermission . COMPONENTS ) ) return
283277
284278 if ( instance ) {
285- this . ctx . hook . emit ( HookEvents . COMPONENT_UPDATED , ...await this . ctx . api . transformCall ( HookEvents . COMPONENT_UPDATED , instance ) )
279+ this . ctx . hook . emit ( HookEvents . COMPONENT_UPDATED , ...await this . backendApi . transformCall ( HookEvents . COMPONENT_UPDATED , instance ) )
286280 } else {
287281 this . ctx . hook . emit ( HookEvents . COMPONENT_UPDATED )
288282 }
@@ -331,15 +325,15 @@ export class DevtoolsPluginApiInstance<TSettings = any> implements DevtoolsPlugi
331325 }
332326
333327 getComponentBounds ( instance : ComponentInstance ) {
334- return this . ctx . api . getComponentBounds ( instance )
328+ return this . backendApi . getComponentBounds ( instance )
335329 }
336330
337331 getComponentName ( instance : ComponentInstance ) {
338- return this . ctx . api . getComponentName ( instance )
332+ return this . backendApi . getComponentName ( instance )
339333 }
340334
341335 getComponentInstances ( app : App ) {
342- return this . ctx . api . getComponentInstances ( app )
336+ return this . backendApi . getComponentInstances ( app )
343337 }
344338
345339 highlightElement ( instance : ComponentInstance ) {
0 commit comments