UNPKG

redux-state-sync

Version:

A middleware for redux to sync state in different tabs

26 lines (21 loc) 735 B
import { connect } from 'react-redux'; import { toggleTodo } from '../actions'; import TodoList from '../components/TodoList'; const getVisibleTodos = (todos, filter) => { switch (filter) { case 'SHOW_COMPLETED': return todos.filter(t => t.get('completed')); case 'SHOW_ACTIVE': return todos.filter(t => !t.get('completed')); case 'SHOW_ALL': default: return todos; } }; const mapStateToProps = state => ({ todos: getVisibleTodos(state.get('todos'), state.get('visibilityFilter')), }); const mapDispatchToProps = dispatch => ({ toggleTodo: id => dispatch(toggleTodo(id)), }); export default connect(mapStateToProps, mapDispatchToProps)(TodoList);