Last active
October 18, 2019 13:12
-
-
Save simontreny/100a509e5a19e6639e206812fa24e6e8 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 { Observable } from "./observable"; | |
export interface Todo { | |
readonly text: string; | |
readonly completed: boolean; | |
} | |
export enum VisibilityFilter { | |
SHOW_ALL, | |
SHOW_COMPLETED, | |
SHOW_ACTIVE, | |
} | |
export class TodoService { | |
readonly todos = new Observable<Todo[]>([]); | |
readonly visibilityFilter = new Observable(VisibilityFilter.SHOW_ALL); | |
addTodo(text: string) { | |
this.todos.set([...this.todos.get(), { text, completed: false }]); | |
} | |
toggleTodo(index: number) { | |
this.todos.set(this.todos.get().map( | |
(todo, i) => (i === index ? { text: todo.text, completed: !todo.completed } : todo) | |
)); | |
} | |
setVisibilityFilter(filter: VisibilityFilter) { | |
this.visibilityFilter.set(filter); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment