iModules Software
The What
The Why
The How
Improve the dev cycle
Immediate feedback
No more constant reloading
Actions, event emitters, multiple stores
Distilled for better understanding
getState()
subscribe()
dispatch()
const changeState = (state, action) => {
switch(action.type){
case 'CHANGE_LETTERS':{
return {...state, letters: action.letters};
}
default:
return state;
}
}
const Component = ({name, handleOnClick}) => (
<div>
Hi! I'm {name}
<button onClick={handleOnClick}>Say Hello!</button>
</div>
)
const Component = ({name, handleOnClick}) => (
<div>
Hi! I'm {name}
<button onClick={handleOnClick}>Say Hello!</button>
</div>
)
const mapStateToProps = (stateProps, ownProps) => ({
name: stateProps.component.name
})
const Component = ({name, handleOnClick}) => (
<div>
Hi! I'm {name}
<button onClick={handleOnClick}>Say Hello!</button>
</div>
)
const mapStateToProps = (stateProps, ownProps) => ({
name: stateProps.component.name
})
const mapDispatchToProps = (dispatch, ownProps) => ({
handleOnClick: (id) => dispatch(sayHello())
})
const Component = ({name, handleOnClick}) => (
<div>
Hi! I'm {name}
<button onClick={handleOnClick}>Say Hello!</button>
</div>
)
const mapStateToProps = (stateProps, ownProps) => ({
name: stateProps.component.name
})
const mapDispatchToProps = (dispatch, ownProps) => ({
handleOnClick: (id) => dispatch(sayHello())
})
const mergeProps = (stateProps, dispatchProps, ownProps) => ({
...stateProps, ...dispatchProps, ...ownProps
})
const Component = ({name, handleOnClick}) => (
<div>
Hi! I'm {name}
<button onClick={handleOnClick}>Say Hello!</button>
</div>
)
const mapStateToProps = (stateProps, ownProps) => ({
name: stateProps.component.name
})
const mapDispatchToProps = (dispatch, ownProps) => ({
handleOnClick: (id) => dispatch(sayHello())
})
const mergeProps = (stateProps, dispatchProps, ownProps) => ({
...stateProps, ...dispatchProps, ...ownProps
})
export default connect(mapStateToProps, mapDispatchToProps, mergeProps)(Component)
No handling of subscribe, or unsubscribe, or getState, or any other nonsense. The connect() function just does it all for us!
Let's get our demo on and have some
(ctional) programming!
fun
Pluralsight: Cory House
Dan Abramov's courses on Egghead.io
Redux documentation @ redux.js.org