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

Allow returning arbitrary data from the handleAction function #7

Merged
merged 4 commits into from
Feb 10, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
cinnabarcaracal marked this conversation as resolved.
Show resolved Hide resolved
}
return (state || s) as any;
};
Expand Down