Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Usage reselect in Redux reducers
// We're adding COMPLETE_ALL_VISIBLE_TODOS and DELETE_ALL_VISIBLE_TODOS
// to the reducers.js example of ReduxExample: Todo List
// http://rackt.org/redux/docs/basics/ExampleTodoList.html > reducers.js
// using the visibleTodosSelector of Computing Derived Data
// http://rackt.org/redux/docs/recipes/ComputingDerivedData.html
// Using this memoized selector function enables reuse of derived data
import {visibleTodosSelector} from 'selectors/TodoSelectors.js';
function todos(state = [], action) {
switch (action.type) {
case COMPLETE_ALL_VISIBLE_TODOS:
const visibleTodos = visibleTodosSelector(state).visibleTodos;
// mark all these todos as completed
break;
case DELETE_ALL_VISIBLE_TODOS:
const visibleTodos = visibleTodosSelector(state).visibleTodos;
// delete all these todos
break;
// ... other cases
default:
return state;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment