Skip to content

Instantly share code, notes, and snippets.

@peteruithoven
Last active October 26, 2015 17:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peteruithoven/348c11afbd10cf81c01d to your computer and use it in GitHub Desktop.
Save peteruithoven/348c11afbd10cf81c01d to your computer and use it in GitHub Desktop.
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