Last active
October 26, 2015 17:16
-
-
Save peteruithoven/348c11afbd10cf81c01d to your computer and use it in GitHub Desktop.
Usage reselect in Redux reducers
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
// 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