@@ -59,7 +59,7 @@ export function addDevtools (app, store) {
5959 makeLocalGetters ( store , modulePath )
6060 payload . state = formatStoreForInspectorState (
6161 getStoreModule ( store . _modules , modulePath ) ,
62- store . _makeLocalGettersCache ,
62+ modulePath === 'root' ? store . getters : store . _makeLocalGettersCache ,
6363 modulePath
6464 )
6565 }
@@ -228,16 +228,45 @@ function formatStoreForInspectorState (module, getters, path) {
228228 }
229229
230230 if ( gettersKeys . length ) {
231- storeState . getters = gettersKeys . map ( ( key ) => ( {
231+ const tree = transformPathsToObjectTree ( getters )
232+ storeState . getters = Object . keys ( tree ) . map ( ( key ) => ( {
232233 key : key . endsWith ( '/' ) ? extractNameFromPath ( key ) : key ,
233234 editable : false ,
234- value : getters [ key ]
235+ value : canThrow ( ( ) => tree [ key ] )
235236 } ) )
236237 }
237238
238239 return storeState
239240}
240241
242+ function transformPathsToObjectTree ( getters ) {
243+ const result = { }
244+ Object . keys ( getters ) . forEach ( key => {
245+ const path = key . split ( '/' )
246+ if ( path . length > 1 ) {
247+ let target = result
248+ const leafKey = path . pop ( )
249+ for ( const p of path ) {
250+ if ( ! target [ p ] ) {
251+ target [ p ] = {
252+ _custom : {
253+ value : { } ,
254+ display : p ,
255+ tooltip : 'Module' ,
256+ abstract : true
257+ }
258+ }
259+ }
260+ target = target [ p ] . _custom . value
261+ }
262+ target [ leafKey ] = canThrow ( ( ) => getters [ key ] )
263+ } else {
264+ result [ key ] = canThrow ( ( ) => getters [ key ] )
265+ }
266+ } )
267+ return result
268+ }
269+
241270function getStoreModule ( moduleMap , path ) {
242271 const names = path . split ( '/' ) . filter ( ( n ) => n )
243272 return names . reduce (
@@ -251,3 +280,11 @@ function getStoreModule (moduleMap, path) {
251280 path === 'root' ? moduleMap : moduleMap . root . _children
252281 )
253282}
283+
284+ function canThrow ( cb ) {
285+ try {
286+ return cb ( )
287+ } catch ( e ) {
288+ return e
289+ }
290+ }
0 commit comments