Skip to content
This repository was archived by the owner on Feb 3, 2020. It is now read-only.

Commit 79f945e

Browse files
Allow returning arbitrary data from the handleAction function
1 parent 8167bba commit 79f945e

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/handle-action.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,14 @@ export default function handleAction<S, AC extends TsActionCreator<any> = any>(
2323
return (state: S | undefined, action: ReturnType<AC>) => {
2424
if (action.type === ac.type && state) {
2525
const draft = createDraft(state);
26-
re(draft, action);
27-
return finishDraft(draft);
26+
const reResult = re(draft, action);
27+
const finishedDraft = finishDraft(draft);
28+
29+
if (finishedDraft === state && reResult !== undefined) {
30+
return reResult;
31+
} else {
32+
return finishedDraft;
33+
}
2834
}
2935
return (state || s) as any;
3036
};

0 commit comments

Comments
 (0)