Created
September 23, 2016 03:40
-
-
Save ManuelDeLeon/06f0a59c4f0759b18c75c8160c4f9f6a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { connect } from 'react-redux' | |
import { toggleTodo } from '../actions' | |
import TodoList from '../components/TodoList' | |
const getVisibleTodos = (todos, filter) => { | |
switch (filter) { | |
case 'SHOW_ALL': | |
return todos | |
case 'SHOW_COMPLETED': | |
return todos.filter(t => t.completed) | |
case 'SHOW_ACTIVE': | |
return todos.filter(t => !t.completed) | |
default: | |
throw new Error('Unknown filter: ' + filter) | |
} | |
} | |
const mapStateToProps = (state) => ({ | |
todos: getVisibleTodos(state.todos, state.visibilityFilter) | |
}) | |
const mapDispatchToProps = ({ | |
onTodoClick: toggleTodo | |
}) | |
const VisibleTodoList = connect( | |
mapStateToProps, | |
mapDispatchToProps | |
)(TodoList) | |
export default VisibleTodoList |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment