Skip to content

Instantly share code, notes, and snippets.

@NetanelBasal
Last active September 10, 2020 11:46
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 NetanelBasal/47654345adcdd0d98927d42bb6601a37 to your computer and use it in GitHub Desktop.
Save NetanelBasal/47654345adcdd0d98927d42bb6601a37 to your computer and use it in GitHub Desktop.
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);
@adamdharrington
Copy link

What's the this context here that you have this.this.getVisibleTodos or is that a typo?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment