Skip to content

Commit 729aecd

Browse files
committed
Fix next state calculation for actions
1 parent e43b16a commit 729aecd

File tree

3 files changed

+30
-13
lines changed

3 files changed

+30
-13
lines changed

dist/hyperapp-devtools.js

Lines changed: 13 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/hyperapp-devtools.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/actions.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,23 @@ import { getPath } from "./selectors"
44

55
import * 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

1626
function 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

Comments
 (0)