@@ -9,94 +9,101 @@ import {
99 Tab ,
1010} from './types'
1111
12- export let isConnecting : boolean = true
13-
14- export let error : string = null
15-
16- export let currentAppName : string = null
17-
18- export let port : string = '3031'
19-
20- export let apps : Apps = { }
21-
22- export let newPortValue : string = ''
23-
24- export let currentTab : Tab = Tab . State
25-
26- export let expandedStatePaths : string [ ] = [ '' ]
27-
28- export const currentApp : Derive < App > = ( state ) =>
29- state . apps [ state . currentAppName ]
30-
31- export const componentsMounted : Derive < Component [ ] > = ( state ) =>
32- Object . keys ( state . currentApp . components ) . reduce (
33- ( aggr , key ) => {
34- if ( state . currentApp . components [ key ] . isMounted ) {
35- return aggr . concat ( state . currentApp . components [ key ] )
36- }
37-
38- return aggr
39- } ,
40- [ ] as Component [ ]
41- )
42-
43- export const componentsUpdateCount : Derive < number > = ( state ) =>
44- state . componentsMounted . reduce (
45- ( aggr , component ) => aggr + component . updateCount ,
46- 0
47- )
48-
49- export const componentsStatePathCount : Derive < number > = ( state ) =>
50- state . componentsMounted . reduce (
51- ( aggr , component ) => aggr + component . paths . length ,
52- 0
53- )
54-
55- export const flushes : Derive < Flush [ ] > = ( state ) =>
56- Object . keys ( state . currentApp . flushes )
57- . sort (
58- ( idA , idB ) =>
59- state . currentApp . flushes [ idB ] . flushId -
60- state . currentApp . flushes [ idA ] . flushId
61- )
62- . map ( ( id ) => state . currentApp . flushes [ id ] )
63-
64- export const flushesMutationsCount : Derive < number > = ( state ) =>
65- state . flushes . reduce ( ( aggr , flush ) => aggr + flush . mutations . length , 0 )
66-
67- export const flushesStatePathCount : Derive < number > = ( state ) =>
68- state . flushes . reduce ( ( aggr , flush ) => {
69- return flush . mutations . reduce (
70- ( aggr , mutation ) =>
71- aggr . includes ( mutation . path ) ? aggr : aggr . concat ( mutation . path ) ,
72- aggr
73- )
74- } , [ ] ) . length
75-
76- export const currentAction : Derive < Action > = ( state ) =>
77- state . currentApp . actions [ state . currentApp . currentActionId ]
78-
79- export let expandAllActionDetails : boolean = false
80-
81- export const expandedComponents : string [ ] = [ ]
12+ type State = {
13+ isConnecting : boolean
14+ error : string
15+ port : string
16+ apps : Apps
17+ currentAppName : string
18+ newPortValue : string
19+ currentTab : Tab
20+ expandedStatePaths : string [ ]
21+ expandAllActionDetails : boolean
22+ expandedComponents : string [ ]
23+ currentAction : Derive < Action >
24+ currentApp : Derive < App >
25+ componentsMounted : Derive < Component [ ] >
26+ componentsUpdateCount : Derive < number >
27+ componentsStatePathCount : Derive < number >
28+ flushes : Derive < Flush [ ] >
29+ flushesMutationsCount : Derive < number >
30+ flushesStatePathCount : Derive < number >
31+ groupedComponents : Derive < GroupedComponents >
32+ }
8233
83- export const groupedComponents : Derive < GroupedComponents > = ( state ) => {
84- const components = state . componentsMounted
34+ const state : State = {
35+ isConnecting : true ,
36+ error : null ,
37+ currentAppName : null ,
38+ port : '3031' ,
39+ apps : { } ,
40+ newPortValue : '' ,
41+ currentTab : Tab . State ,
42+ expandedStatePaths : [ '' ] ,
43+ expandAllActionDetails : false ,
44+ expandedComponents : [ ] ,
45+ currentApp : ( state ) => state . apps [ state . currentAppName ] ,
46+ componentsMounted : ( state ) =>
47+ Object . keys ( state . currentApp . components ) . reduce (
48+ ( aggr , key ) => {
49+ if ( state . currentApp . components [ key ] . isMounted ) {
50+ return aggr . concat ( state . currentApp . components [ key ] )
51+ }
8552
86- return components . reduce (
87- ( aggr , component ) => {
88- if ( aggr [ component . name ] ) {
89- aggr [ component . name ] . components . push ( component )
90- } else {
91- aggr [ component . name ] = {
92- name : component . name ,
93- components : [ component ] ,
94- isCollapsed : ! state . expandedComponents . includes ( component . name ) ,
53+ return aggr
54+ } ,
55+ [ ] as Component [ ]
56+ ) ,
57+ componentsUpdateCount : ( state ) =>
58+ state . componentsMounted . reduce (
59+ ( aggr , component ) => aggr + component . updateCount ,
60+ 0
61+ ) ,
62+ componentsStatePathCount : ( state ) =>
63+ state . componentsMounted . reduce (
64+ ( aggr , component ) => aggr + component . paths . length ,
65+ 0
66+ ) ,
67+ flushes : ( state ) =>
68+ Object . keys ( state . currentApp . flushes )
69+ . sort (
70+ ( idA , idB ) =>
71+ state . currentApp . flushes [ idB ] . flushId -
72+ state . currentApp . flushes [ idA ] . flushId
73+ )
74+ . map ( ( id ) => state . currentApp . flushes [ id ] ) ,
75+ flushesMutationsCount : ( state ) =>
76+ state . flushes . reduce ( ( aggr , flush ) => aggr + flush . mutations . length , 0 ) ,
77+ flushesStatePathCount : ( state ) =>
78+ state . flushes . reduce ( ( aggr , flush ) => {
79+ return flush . mutations . reduce (
80+ ( aggr , mutation ) =>
81+ aggr . includes ( mutation . path ) ? aggr : aggr . concat ( mutation . path ) ,
82+ aggr
83+ )
84+ } , [ ] ) . length ,
85+ currentAction : ( state ) =>
86+ state . currentApp . actions [ state . currentApp . currentActionId ] ,
87+ groupedComponents ( state ) {
88+ const components = state . componentsMounted
89+
90+ return components . reduce (
91+ ( aggr , component ) => {
92+ if ( aggr [ component . name ] ) {
93+ aggr [ component . name ] . components . push ( component )
94+ } else {
95+ aggr [ component . name ] = {
96+ name : component . name ,
97+ components : [ component ] ,
98+ isCollapsed : ! state . expandedComponents . includes ( component . name ) ,
99+ }
95100 }
96- }
97101
98- return aggr
99- } ,
100- { } as GroupedComponents
101- )
102+ return aggr
103+ } ,
104+ { } as GroupedComponents
105+ )
106+ } ,
102107}
108+
109+ export default state
0 commit comments