Redux: Getting Functional on Your Apps
With just callbacks or promises, one can almost read the code as non-functional, with a few extra parens 'n things thrown in. If you ignore the yellow parts below, it could almost be C or Java.
whatever.then(()=>{
code
code
code
})
"then"... the code in curly braces happens.
But in Redux, we get things like this fragment from https://github.com/reduxjs/redux/blob/master/examples/todos/src/containers/VisibleTodoList.js
const mapDispatchToProps = dispatch => ({
toggleTodo: id => dispatch(toggleTodo(id))
})
export default connect(
mapStateToProps,
mapDispatchToProps
)(TodoList)
Here, mapDispatchToProps is a function which takes a function (dispatch) as its argument
and returns an object who's property's value is also a function.
Then mapDispatchToProps is used as an argument to the connect(..) function
which returns a function whose argument is TodoList, a component which is also a function.
So if you don't understand that functions can be values, you'll hardly be able to function.
whatever.then(()=>{
code
code
code
})
"then"... the code in curly braces happens.
But in Redux, we get things like this fragment from https://github.com/reduxjs/redux/blob/master/examples/todos/src/containers/VisibleTodoList.js
const mapDispatchToProps = dispatch => ({
toggleTodo: id => dispatch(toggleTodo(id))
})
export default connect(
mapStateToProps,
mapDispatchToProps
)(TodoList)
Here, mapDispatchToProps is a function which takes a function (dispatch) as its argument
and returns an object who's property's value is also a function.
Then mapDispatchToProps is used as an argument to the connect(..) function
which returns a function whose argument is TodoList, a component which is also a function.
So if you don't understand that functions can be values, you'll hardly be able to function.
Comments
Post a Comment