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

Commit

Permalink
Allow returning arbitrary data from the handleAction function
Browse files Browse the repository at this point in the history
  • Loading branch information
cinnabarcaracal committed Feb 5, 2019
1 parent 8167bba commit 79f945e
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/handle-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,14 @@ export default function handleAction<S, AC extends TsActionCreator<any> = any>(
return (state: S | undefined, action: ReturnType<AC>) => {
if (action.type === ac.type && state) {
const draft = createDraft(state);
re(draft, action);
return finishDraft(draft);
const reResult = re(draft, action);
const finishedDraft = finishDraft(draft);

if (finishedDraft === state && reResult !== undefined) {
return reResult;
} else {
return finishedDraft;
}
}
return (state || s) as any;
};
Expand Down

0 comments on commit 79f945e

Please sign in to comment.