@@ -127,7 +127,7 @@ export function setupPlugin (api: DevtoolsApi, app: App, Vue) {
127
127
api . on . editInspectorState ( ( payload ) => {
128
128
if ( payload . inspectorId === VUEX_INSPECTOR_ID ) {
129
129
let path = payload . path
130
- if ( payload . nodeId !== 'root' ) {
130
+ if ( payload . nodeId !== VUEX_ROOT_PATH ) {
131
131
path = [
132
132
...payload . nodeId . substring ( 0 , payload . nodeId . length - 1 ) . split ( '/' ) ,
133
133
...path ,
@@ -380,9 +380,11 @@ const TAG_NAMESPACED = {
380
380
backgroundColor : DARK ,
381
381
}
382
382
383
+ const VUEX_ROOT_PATH = '__vdt_root'
384
+
383
385
function formatStoreForInspectorTree ( module , path ) : CustomInspectorNode {
384
386
return {
385
- id : path || 'root' ,
387
+ id : path || VUEX_ROOT_PATH ,
386
388
// all modules end with a `/`, we want the last segment only
387
389
// cart/ -> cart
388
390
// nested/cart/ -> cart
@@ -400,7 +402,7 @@ function formatStoreForInspectorTree (module, path): CustomInspectorNode {
400
402
function flattenStoreForInspectorTree ( result : CustomInspectorNode [ ] , module , filter : string , path : string ) {
401
403
if ( path . includes ( filter ) ) {
402
404
result . push ( {
403
- id : path || 'root' ,
405
+ id : path || VUEX_ROOT_PATH ,
404
406
label : path . endsWith ( '/' ) ? path . slice ( 0 , path . length - 1 ) : path || 'Root' ,
405
407
tags : module . namespaced ? [ TAG_NAMESPACED ] : [ ] ,
406
408
} )
@@ -411,7 +413,7 @@ function flattenStoreForInspectorTree (result: CustomInspectorNode[], module, fi
411
413
}
412
414
413
415
function extractNameFromPath ( path : string ) {
414
- return path && path !== 'root' ? path . split ( '/' ) . slice ( - 2 , - 1 ) [ 0 ] : 'Root'
416
+ return path && path !== VUEX_ROOT_PATH ? path . split ( '/' ) . slice ( - 2 , - 1 ) [ 0 ] : 'Root'
415
417
}
416
418
417
419
function formatStoreForInspectorState ( module , getters , path ) : CustomInspectorState {
@@ -423,9 +425,9 @@ function formatStoreForInspectorState (module, getters, path): CustomInspectorSt
423
425
} ) ) ,
424
426
}
425
427
426
- getters = ! module . namespaced || path === 'root' ? module . context . getters : getters [ path ]
428
+ getters = ! module . namespaced || path === VUEX_ROOT_PATH ? module . context . getters : getters [ path ]
427
429
let gettersKeys = Object . keys ( getters )
428
- const shouldPickGetters = ! module . namespaced && path !== 'root'
430
+ const shouldPickGetters = ! module . namespaced && path !== VUEX_ROOT_PATH
429
431
if ( shouldPickGetters ) {
430
432
// Only pick the getters defined in the non-namespaced module
431
433
const definedGettersKeys = Object . keys ( module . _rawModule . getters ?? { } )
@@ -485,13 +487,13 @@ function getStoreModule (moduleMap, path) {
485
487
const names = path . split ( '/' ) . filter ( ( n ) => n )
486
488
return names . reduce (
487
489
( module , moduleName , i ) => {
488
- const child = module [ moduleName ]
490
+ const child = module [ moduleName === VUEX_ROOT_PATH ? 'root' : moduleName ]
489
491
if ( ! child ) {
490
492
throw new Error ( `Missing module "${ moduleName } " for path "${ path } ".` )
491
493
}
492
494
return i === names . length - 1 ? child : child . _children
493
495
} ,
494
- path === 'root' ? moduleMap : moduleMap . root . _children ,
496
+ path === VUEX_ROOT_PATH ? moduleMap : moduleMap . root . _children ,
495
497
)
496
498
}
497
499
0 commit comments