Skip to content

Instantly share code, notes, and snippets.

@mattbajorek
Created March 26, 2020 02:52
Show Gist options
  • Save mattbajorek/a8d2cf95dba6c9be01e234c93b3a1ca6 to your computer and use it in GitHub Desktop.
Save mattbajorek/a8d2cf95dba6c9be01e234c93b3a1ca6 to your computer and use it in GitHub Desktop.
todos-redux-to-react-sweet-state todos selector
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