Created
March 26, 2020 02:52
-
-
Save mattbajorek/a8d2cf95dba6c9be01e234c93b3a1ca6 to your computer and use it in GitHub Desktop.
todos-redux-to-react-sweet-state todos selector
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
import makeSelectorsIntoHooks from '../utils' | |
import todosStore from './todos.store' | |
import { VisibilityFilters } from '../visibilityFilter/visibilityFilter.store' | |
const todoSelectors = { | |
useTodosActions: null, | |
useVisibleTodos: (todos, visibilityFilter) => { | |
switch (visibilityFilter) { | |
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: ' + visibilityFilter) | |
} | |
} | |
} | |
export default makeSelectorsIntoHooks(todoSelectors, todosStore) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment