@@ -4,13 +4,23 @@ import { getPath } from "./selectors"
44
55import * as api from "./api"
66
7- function mergeResult ( state : any , event : api . ActionEvent ) : any {
7+ function getPreviousState ( action : api . AppAction ) : any {
8+ if ( action . actions . length > 0 ) {
9+ const child = action . actions [ action . actions . length - 1 ]
10+ return child . done ? child . nextState : child . previousState
11+ }
12+
13+ return action . previousState
14+ }
15+
16+ function mergeResult ( action : api . AppAction , event : api . ActionEvent ) : any {
817 if ( event && event . result ) {
9- const action = event . action . split ( "." )
10- action . pop ( )
11- return merge ( state , action , event . result )
18+ const path = event . action . split ( "." )
19+ path . pop ( )
20+ return merge ( getPreviousState ( action ) , path , event . result )
1221 }
13- return state
22+
23+ return getPreviousState ( action )
1424}
1525
1626function isCurrentAction ( action : api . AppAction ) : boolean {
@@ -56,7 +66,7 @@ function appendActionEvent(
5666 ...action ,
5767 done : true ,
5868 actionResult : event . result ,
59- nextState : mergeResult ( action . previousState , event )
69+ nextState : mergeResult ( action , event )
6070 }
6171 } else {
6272 // error case
0 commit comments