react-controllables
react-controllables copied to clipboard
Do we need boundActionCreators inside reducer state?
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) => ({
})
)
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})
+1 and please npm publish 0.7