mirror of
https://github.com/leporello-js/leporello-js
synced 2026-01-14 05:14:28 -08:00
redux example init
This commit is contained in:
30
docs/examples/todos/src/containers/VisibleTodoList.js
Normal file
30
docs/examples/todos/src/containers/VisibleTodoList.js
Normal file
@@ -0,0 +1,30 @@
|
||||
import { connect } from 'react-redux'
|
||||
import { toggleTodo } from '../actions'
|
||||
import TodoList from '../components/TodoList'
|
||||
import { VisibilityFilters } from '../actions'
|
||||
|
||||
const getVisibleTodos = (todos, filter) => {
|
||||
switch (filter) {
|
||||
case VisibilityFilters.SHOW_ALL:
|
||||
return todos
|
||||
case VisibilityFilters.SHOW_COMPLETED:
|
||||
return todos.filter(t => t.completed)
|
||||
case VisibilityFilters.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 = dispatch => ({
|
||||
toggleTodo: id => dispatch(toggleTodo(id))
|
||||
})
|
||||
|
||||
export default connect(
|
||||
mapStateToProps,
|
||||
mapDispatchToProps
|
||||
)(TodoList)
|
||||
Reference in New Issue
Block a user