@@ -17,8 +17,8 @@ function isCurrentAction(action: api.AppAction): boolean {
1717 return false
1818 }
1919
20- const length = action . nestedActions . length
21- return length === 0 || action . nestedActions [ length - 1 ] . done
20+ const length = action . actions . length
21+ return length === 0 || action . actions [ length - 1 ] . done
2222}
2323
2424/**
@@ -41,13 +41,13 @@ function appendActionEvent(
4141 done : false ,
4242 collapsed : false ,
4343 actionData : event . data ,
44- nestedActions : [ ] ,
44+ actions : [ ] ,
4545 previousState : action . previousState
4646 }
4747
4848 return {
4949 ...action ,
50- nestedActions : action . nestedActions . concat ( nestedAction )
50+ actions : action . actions . concat ( nestedAction )
5151 }
5252 } else if ( action . name === event . action ) {
5353 // the previous call is now complete: set to done and compute the result
@@ -65,19 +65,41 @@ function appendActionEvent(
6565 }
6666 } else {
6767 // there are already some nested actions: call recursivelly
68- const nested = action . nestedActions
68+ const nested = action . actions
6969 const nestedAction = nested [ nested . length - 1 ]
7070 const newNestedAction = appendActionEvent ( nestedAction , event )
7171 if ( nestedAction === newNestedAction ) {
7272 return action
7373 }
7474 return {
7575 ...action ,
76- nestedActions : nested . slice ( 0 , nested . length - 1 ) . concat ( newNestedAction )
76+ actions : nested . slice ( 0 , nested . length - 1 ) . concat ( newNestedAction )
7777 }
7878 }
7979}
8080
81+ function toggleAction (
82+ runs : api . Runs ,
83+ runId : string ,
84+ actionPath : number [ ]
85+ ) : api . Runs {
86+ const path : any [ ] = [ runId ]
87+ actionPath . forEach ( index => {
88+ path . push ( "actions" , index )
89+ } )
90+ path . push ( "collapsed" )
91+
92+ const collapsed = get ( runs , path )
93+ if ( typeof collapsed !== "boolean" ) {
94+ console . log ( "WARN: try to collapse invalid action, path: " , actionPath )
95+ return runs
96+ }
97+
98+ return set ( runs , path , ! collapsed )
99+ }
100+
101+ export const INITIAL_ACTION = "%%% INITIAL STATE %%%"
102+
81103export const actions : ActionsType < api . State , api . Actions > = {
82104 log : ( event : api . RuntimeEvent ) => state => {
83105 return { logs : state . logs . concat ( [ event ] ) }
@@ -86,10 +108,10 @@ export const actions: ActionsType<api.State, api.Actions> = {
86108 const runs = { ...state . runs }
87109
88110 const action : api . AppAction = {
89- name : "Initial State" ,
111+ name : INITIAL_ACTION ,
90112 done : true ,
91113 collapsed : false ,
92- nestedActions : [ ] ,
114+ actions : [ ] ,
93115 previousState : null ,
94116 nextState : event . state
95117 }
@@ -116,7 +138,7 @@ export const actions: ActionsType<api.State, api.Actions> = {
116138 selectedAction = {
117139 done : false ,
118140 collapsed : false ,
119- nestedActions : [ ] ,
141+ actions : [ ] ,
120142 name : event . action ,
121143 actionData : event . data ,
122144 previousState : prevAction . nextState
@@ -141,10 +163,8 @@ export const actions: ActionsType<api.State, api.Actions> = {
141163 return { runs }
142164 } ,
143165 toggleAction : ( payload : api . ToggleActionPayload ) => state => {
144- const { run, actionId } = payload
145- const path = [ run , "actions" , actionId , "collapsed" ]
146- const collapsed = get ( state . runs , path )
147- const runs = set ( state . runs , path , ! collapsed )
166+ const { run, path } = payload
167+ const runs = toggleAction ( state . runs , run , path )
148168 return { runs }
149169 } ,
150170 select : ( selectedAction : api . AppAction | null ) => {
0 commit comments