@@ -103,7 +103,7 @@ export function setupPlugin (api: DevtoolsApi, app: App, Vue) {
103
103
payload . rootNodes = nodes
104
104
} else {
105
105
payload . rootNodes = [
106
- formatStoreForInspectorTree ( store . _modules . root , '' ) ,
106
+ formatStoreForInspectorTree ( store . _modules . root , 'Root' , ' ') ,
107
107
]
108
108
}
109
109
}
@@ -381,19 +381,22 @@ const TAG_NAMESPACED = {
381
381
}
382
382
383
383
const VUEX_ROOT_PATH = '__vdt_root'
384
+ const VUEX_MODULE_PATH_SEPARATOR = '[vdt]'
385
+ const VUEX_MODULE_PATH_SEPARATOR_REG = / \[ v d t \] / g
384
386
385
- function formatStoreForInspectorTree ( module , path ) : CustomInspectorNode {
387
+ function formatStoreForInspectorTree ( module , moduleName : string , path : string ) : CustomInspectorNode {
386
388
return {
387
- id : path || VUEX_ROOT_PATH ,
389
+ id : path ?? VUEX_ROOT_PATH ,
388
390
// all modules end with a `/`, we want the last segment only
389
391
// cart/ -> cart
390
392
// nested/cart/ -> cart
391
- label : extractNameFromPath ( path ) ,
393
+ label : moduleName ,
392
394
tags : module . namespaced ? [ TAG_NAMESPACED ] : [ ] ,
393
- children : Object . keys ( module . _children ) . map ( ( moduleName ) =>
395
+ children : Object . keys ( module . _children ) . map ( ( key ) =>
394
396
formatStoreForInspectorTree (
395
- module . _children [ moduleName ] ,
396
- path + moduleName + '/' ,
397
+ module . _children [ key ] ,
398
+ key ,
399
+ `${ path } ${ key } ${ VUEX_MODULE_PATH_SEPARATOR } ` ,
397
400
) ,
398
401
) ,
399
402
}
@@ -403,17 +406,17 @@ function flattenStoreForInspectorTree (result: CustomInspectorNode[], module, fi
403
406
if ( path . includes ( filter ) ) {
404
407
result . push ( {
405
408
id : path || VUEX_ROOT_PATH ,
406
- label : path . endsWith ( '/' ) ? path . slice ( 0 , path . length - 1 ) : path || 'Root' ,
409
+ label : path . endsWith ( VUEX_MODULE_PATH_SEPARATOR ) ? path . slice ( 0 , path . length - 1 ) : path || 'Root' ,
407
410
tags : module . namespaced ? [ TAG_NAMESPACED ] : [ ] ,
408
411
} )
409
412
}
410
413
Object . keys ( module . _children ) . forEach ( moduleName => {
411
- flattenStoreForInspectorTree ( result , module . _children [ moduleName ] , filter , path + moduleName + '/' )
414
+ flattenStoreForInspectorTree ( result , module . _children [ moduleName ] , filter , path + moduleName + VUEX_MODULE_PATH_SEPARATOR )
412
415
} )
413
416
}
414
417
415
418
function extractNameFromPath ( path : string ) {
416
- return path && path !== VUEX_ROOT_PATH ? path . split ( '/' ) . slice ( - 2 , - 1 ) [ 0 ] : 'Root'
419
+ return path && path !== VUEX_ROOT_PATH ? path . split ( VUEX_MODULE_PATH_SEPARATOR ) . slice ( - 2 , - 1 ) [ 0 ] : 'Root'
417
420
}
418
421
419
422
function formatStoreForInspectorState ( module , getters , path ) : CustomInspectorState {
@@ -425,7 +428,8 @@ function formatStoreForInspectorState (module, getters, path): CustomInspectorSt
425
428
} ) ) ,
426
429
}
427
430
428
- getters = ! module . namespaced || path === VUEX_ROOT_PATH ? module . context . getters : getters [ path ]
431
+ const pathWithSlashes = path . replace ( VUEX_MODULE_PATH_SEPARATOR_REG , '/' )
432
+ getters = ! module . namespaced || path === VUEX_ROOT_PATH ? module . context . getters : getters [ pathWithSlashes ]
429
433
let gettersKeys = Object . keys ( getters )
430
434
const shouldPickGetters = ! module . namespaced && path !== VUEX_ROOT_PATH
431
435
if ( shouldPickGetters ) {
@@ -484,7 +488,7 @@ function transformPathsToObjectTree (getters) {
484
488
}
485
489
486
490
function getStoreModule ( moduleMap , path ) {
487
- const names = path . split ( '/' ) . filter ( ( n ) => n )
491
+ const names = path . split ( VUEX_MODULE_PATH_SEPARATOR ) . filter ( ( n ) => n )
488
492
return names . reduce (
489
493
( module , moduleName , i ) => {
490
494
const child = module [ moduleName === VUEX_ROOT_PATH ? 'root' : moduleName ]
0 commit comments