Should reducers clone initalState to guard against mutation?
lsanders opened this issue · comments
Larry commented
Is your feature request related to a problem? Please describe.
It's easy to accidentally mutate the initialState in reducers, especially from tests.
Describe the solution you'd like
Guard against mutation for initialState.
Describe alternatives you've considered
I really wouldn't want to introduce immutablejs, but maybe just lodash cloneDeep in the reducer:
export const initialState: ContainerState = {
someDeepObject: new Map<string, ISomeInterface>(),
};
function myReducer(
state: ContainerState = cloneDeep(initialState),
action: ContainerActions): ContainerState {
switch (action.type) {
Any other ideas?
Additional context
Thanks for the typescript fork of the awesome boilerplate!
Can Sahin commented
Can Sahin commented
Closing since no response and its unclear. Please open it back if you feel like