-
Notifications
You must be signed in to change notification settings - Fork 346
/
todos.service.ts
43 lines (36 loc) · 964 Bytes
/
todos.service.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { TodosStore } from './todos.store';
import { createTodo, Todo } from './todo.model';
import { Injectable } from '@angular/core';
import { VISIBILITY_FILTER } from '../filter/filter.model';
import { ID, action } from '@datorama/akita';
@Injectable({ providedIn: 'root' })
export class TodosService {
constructor(private todosStore: TodosStore) {}
@action('Update filter')
updateFilter(filter: VISIBILITY_FILTER) {
this.todosStore.update({
ui: {
filter
}
});
}
complete({ id, completed }: Todo) {
this.todosStore.update(id, { completed });
}
add(title: string) {
const todo = createTodo(title);
this.todosStore.add(todo);
}
delete(id: ID) {
this.todosStore.remove(id);
}
checkAll(completed: boolean) {
this.todosStore.update(null, {
completed
});
}
move(index: number) {
console.log('TCL: move -> index', index);
this.todosStore.move(index, index - 1);
}
}