Last active
September 10, 2020 11:46
-
-
Save NetanelBasal/47654345adcdd0d98927d42bb6601a37 to your computer and use it in GitHub Desktop.
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 { TodosState, todosStore, TodosStore } from './todos.store'; | |
import { Todo, VISIBILITY_FILTER } from './todo.model'; | |
import { QueryEntity } from '@datorama/akita'; | |
import { combineLatest } from 'rxjs'; | |
export class TodosQuery extends QueryEntity<TodosState, Todo> { | |
selectVisibilityFilter$ = this.select(state => state.ui.filter); | |
selectVisibleTodos$ = combineLatest([ | |
this.selectVisibilityFilter$, | |
this.selectAll() | |
]).pipe( | |
map(([filter, todos]) => | |
this.this.getVisibleTodos(filter, todos)) | |
); | |
constructor(protected store: TodosStore) { | |
super(store); | |
} | |
private getVisibleTodos(filter: string, todos: Todo[]): Todo[] { | |
switch (filter) { | |
case VISIBILITY_FILTER.SHOW_COMPLETED: | |
return todos.filter(t => t.completed); | |
case VISIBILITY_FILTER.SHOW_ACTIVE: | |
return todos.filter(t => !t.completed); | |
default: | |
return todos; | |
} | |
} | |
} | |
export const todosQuery = new TodosQuery(todosStore); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What's the
this
context here that you havethis.this.getVisibleTodos
or is that a typo?