@@ -3,10 +3,10 @@ import {
3
3
hasPluginPermission ,
4
4
HookEvents ,
5
5
PluginPermission ,
6
- set ,
7
6
getPluginDefaultSettings ,
8
7
getPluginSettings ,
9
- setPluginSettings
8
+ setPluginSettings ,
9
+ StateEditor
10
10
} from '@vue-devtools/shared-utils'
11
11
import {
12
12
Hooks ,
@@ -25,17 +25,22 @@ import {
25
25
import { DevtoolsHookable } from './hooks'
26
26
import { BackendContext } from './backend-context'
27
27
import { Plugin } from './plugin'
28
+ import { DevtoolsBackend } from './backend'
29
+ import { AppRecord } from './app-record'
28
30
29
31
let backendOn : DevtoolsHookable
30
32
const pluginOn : DevtoolsHookable [ ] = [ ]
31
33
32
34
export class DevtoolsApi {
33
35
bridge : Bridge
34
36
ctx : BackendContext
37
+ backend : DevtoolsBackend
38
+ stateEditor : StateEditor = new StateEditor ( )
35
39
36
- constructor ( bridge : Bridge , ctx : BackendContext ) {
37
- this . bridge = bridge
40
+ constructor ( backend : DevtoolsBackend , ctx : BackendContext ) {
41
+ this . backend = backend
38
42
this . ctx = ctx
43
+ this . bridge = ctx . bridge
39
44
if ( ! backendOn ) { backendOn = new DevtoolsHookable ( ctx ) }
40
45
}
41
46
@@ -171,7 +176,7 @@ export class DevtoolsApi {
171
176
path : arrayPath ,
172
177
type,
173
178
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 ) )
175
180
} )
176
181
return payload . componentInstance
177
182
}
@@ -240,37 +245,26 @@ export class DevtoolsApi {
240
245
path : arrayPath ,
241
246
type,
242
247
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 ) )
244
249
} )
245
250
}
246
251
}
247
252
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
-
263
253
export class DevtoolsPluginApiInstance < TSettings = any > implements DevtoolsPluginApi < TSettings > {
264
254
bridge : Bridge
265
255
ctx : BackendContext
266
256
plugin : Plugin
257
+ appRecord : AppRecord
258
+ backendApi : DevtoolsApi
267
259
on : DevtoolsHookable
268
260
private defaultSettings : TSettings
269
261
270
- constructor ( plugin : Plugin , ctx : BackendContext ) {
262
+ constructor ( plugin : Plugin , appRecord : AppRecord , ctx : BackendContext ) {
271
263
this . bridge = ctx . bridge
272
264
this . ctx = ctx
273
265
this . plugin = plugin
266
+ this . appRecord = appRecord
267
+ this . backendApi = appRecord . backend . api
274
268
this . defaultSettings = getPluginDefaultSettings ( plugin . descriptor . settings )
275
269
this . on = new DevtoolsHookable ( ctx , plugin )
276
270
pluginOn . push ( this . on )
@@ -282,7 +276,7 @@ export class DevtoolsPluginApiInstance<TSettings = any> implements DevtoolsPlugi
282
276
if ( ! this . enabled || ! this . hasPermission ( PluginPermission . COMPONENTS ) ) return
283
277
284
278
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 ) )
286
280
} else {
287
281
this . ctx . hook . emit ( HookEvents . COMPONENT_UPDATED )
288
282
}
@@ -331,15 +325,15 @@ export class DevtoolsPluginApiInstance<TSettings = any> implements DevtoolsPlugi
331
325
}
332
326
333
327
getComponentBounds ( instance : ComponentInstance ) {
334
- return this . ctx . api . getComponentBounds ( instance )
328
+ return this . backendApi . getComponentBounds ( instance )
335
329
}
336
330
337
331
getComponentName ( instance : ComponentInstance ) {
338
- return this . ctx . api . getComponentName ( instance )
332
+ return this . backendApi . getComponentName ( instance )
339
333
}
340
334
341
335
getComponentInstances ( app : App ) {
342
- return this . ctx . api . getComponentInstances ( app )
336
+ return this . backendApi . getComponentInstances ( app )
343
337
}
344
338
345
339
highlightElement ( instance : ComponentInstance ) {
0 commit comments