Skip to content
This repository was archived by the owner on Jul 8, 2021. It is now read-only.

@Action - samples in the README and articles are incorrect? #45

Open
lanovoy opened this issue Mar 6, 2018 · 0 comments
Open

@Action - samples in the README and articles are incorrect? #45

lanovoy opened this issue Mar 6, 2018 · 0 comments

Comments

@lanovoy
Copy link

lanovoy commented Mar 6, 2018

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...

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant