@@ -22,39 +22,44 @@ export const PINIA_ROOT_ID = '_root'
22
22
export function formatStoreForInspectorTree (
23
23
store : StoreGeneric | Pinia
24
24
) : CustomInspectorNode {
25
- return '$id' in store
25
+ return isPinia ( store )
26
26
? {
27
- id : store . $id ,
28
- label : store . $id ,
29
- }
30
- : {
31
27
id : PINIA_ROOT_ID ,
32
28
label : PINIA_ROOT_LABEL ,
33
29
}
30
+ : {
31
+ id : store . $id ,
32
+ label : store . $id ,
33
+ }
34
34
}
35
35
36
36
export function formatStoreForInspectorState (
37
37
store : StoreGeneric | Pinia
38
38
) : CustomInspectorState {
39
39
if ( isPinia ( store ) ) {
40
+ const storeNames = Array . from ( store . _s . keys ( ) )
41
+ const storeMap = store . _s
40
42
const state : CustomInspectorState = {
41
- state : Object . keys ( store . state . value ) . map ( ( storeId ) => ( {
43
+ state : storeNames . map ( ( storeId ) => ( {
42
44
editable : true ,
43
45
key : storeId ,
44
46
value : store . state . value [ storeId ] ,
45
47
} ) ) ,
48
+ getters : storeNames
49
+ . filter ( ( id ) => storeMap . get ( id ) ! . _getters )
50
+ . map ( ( id ) => {
51
+ const store = storeMap . get ( id ) !
52
+
53
+ return {
54
+ editable : false ,
55
+ key : id ,
56
+ value : store . _getters ! . reduce ( ( getters , key ) => {
57
+ getters [ key ] = store [ key ]
58
+ return getters
59
+ } , { } as Record < string , any > ) ,
60
+ }
61
+ } ) ,
46
62
}
47
- // TODO: use this version when possible
48
- // Object.keys(store.state.value).forEach((storeId) => {
49
- // const currentState = store.state.value[storeId]
50
- // state[storeId] = Object.keys(currentState).map((key) => ({
51
- // // is not possible to made editable because no way to get the storeId in
52
- // // edit inspector state callback
53
- // editable: false,
54
- // key,
55
- // value: currentState[key],
56
- // }))
57
- // })
58
63
59
64
return state
60
65
}
0 commit comments