-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #89 from richardcrng/remove-mutate
Remove mutate
- Loading branch information
Showing
10 changed files
with
252 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,19 @@ | ||
export const leafReducerCustom = (reducersDict, leafState, { leaf = {}, payload }, wholeState) => { | ||
const { creatorKey } = leaf; | ||
import produce from 'immer' | ||
|
||
if (Object.keys(reducersDict).includes(creatorKey)) { | ||
const logic = reducersDict[creatorKey] | ||
return logic.reducer(leafState, { payload }, wholeState) | ||
export const leafReducerCustom = (reducersDict, leafState, action, wholeState) => { | ||
const { leaf: { creatorKey } } = action; | ||
|
||
return Object.keys(reducersDict).includes(creatorKey) | ||
? applyReducer(reducersDict[creatorKey], leafState, action, wholeState) | ||
: leafState | ||
} | ||
|
||
const applyReducer = (config, leafState, action, wholeState) => { | ||
if (config.mutate) { | ||
return produce(leafState, draftLeafState => { | ||
config.reducer(draftLeafState, action, wholeState) | ||
}) | ||
} else { | ||
return leafState | ||
return config.reducer(leafState, action, wholeState) | ||
} | ||
} |
Oops, something went wrong.