ngrx-actions
ngrx-actions copied to clipboard
@Action - samples in the README and articles are incorrect?
README and article samples are looking like we can mutate state object directly and don't have to return anything from the reducer function. It doesn't seem to work... If I do something like:
@Action(LoadAction)
public load(state: IState, action: LoadAction) {
state.isLoading: true,
state.isLoaded: false,
state.hasError: false,
state.error: null
}
It wouldn't work throwing exception about read-only variable modifications prohibited in the strict mode.
But if I change it to normal pure-function reducer, it will work just fine:
@Action(LoadAction)
public load(state: IState, action: LoadAction) {
return Object.assign({}, state, {
isLoading: true,
isLoaded: false,
hasError: false,
error: null
});
}
Tbh, the original idea of reducers as pure-functions is great... Sample code in the README looks like if it's a side-effect function with state mutation... if that's the case why then separate @Effect from @Action ? They are essentially the same...