react-controllables icon indicating copy to clipboard operation
react-controllables copied to clipboard

Do we need boundActionCreators inside reducer state?

Open istarkov opened this issue 9 years ago • 2 comments

react-controllables my favorite react component and I use it everywhere, and I really like new changes to it.

Here https://github.com/matthewwithanm/react-controllables/blob/master/src/index.js#L60 IMHO calling reducers from reducers can cause unpredictable results. (setState() does not immediately mutate this.state)

It would be nice to simplify @conrollable syntax, like here redux-actions handleActions method. instead of this

@controllable({
  reducers: {
    onChangeFocus(state, v) {
      return {...state, focus: v};
    },
  },
  initialize(props) {
  }
})

do this

@controllable({
    onChangeFocus(state, v) {
      return {...state, focus: v};
    },
  },
  (props) => ({
  })
)

istarkov avatar Aug 18 '15 09:08 istarkov

Also I think you need to hold reducers state not in ControllableWrapper this.state directly. It is impossible to remove key from reducer state in such situation. example:

@controllable({
  reducers: {
    onChangeFocus(state, v) {
      if (v) {
        return {...state, focus: v};
      }
      // remove focus key from state
      const {focus, ...other} = state;
      return other;
    },
  },
  initialize(props) {
  }
})

in order that setState merges prev state with current, such key removal (calling onChangeFocus(false)) does not affect on state inside ControllableWrapper.

It's better to move state inside ControllableWrapper state.reducersState to emulate replaceState. Updating state as this.setState({reducersState: newState})

istarkov avatar Aug 18 '15 09:08 istarkov

+1 and please npm publish 0.7

b2whats avatar Aug 26 '15 18:08 b2whats