fix(challengeCrud): error in dev

This commit is contained in:
thomas
2022-12-16 14:26:14 +01:00
parent cc1e2c147c
commit df832c6850

View File

@@ -1,58 +0,0 @@
import { Injectable } from '@angular/core';
import { ComponentStore, tapResponse } from '@ngrx/component-store';
import { pipe, switchMap, tap } from 'rxjs';
import { Todo } from './todo.model';
import { TodoService } from './todo.service';
@Injectable()
export class AppStore extends ComponentStore<{
todos: Todo[];
loading: boolean;
}> {
readonly todos$ = this.select((state) => state.todos);
readonly loading$ = this.select((state) => state.loading);
readonly person$;
readonly vm$ = this.select({
todos: this.todos$,
loading: this.loading$,
});
constructor(private todoService: TodoService) {
super({ todos: [], loading: false });
}
private readonly updateTodos = this.updater((state, todo: Todo) => ({
loading: false,
todos: state.todos.map((t) => (t.id === todo.id ? { ...todo } : t)),
}));
readonly fetchTodo = this.effect<void>(
pipe(
tap(() => this.patchState({ loading: true })),
switchMap(() =>
this.todoService.getAllTodo().pipe(
tapResponse(
(todos) => this.patchState({ todos, loading: false }),
(_) => _
)
)
)
)
);
readonly updateTodo = this.effect<number>(
pipe(
tap(() => this.patchState({ loading: true })),
switchMap((id) =>
this.todoService.update(id).pipe(
tapResponse(
(todo) => this.updateTodos(todo),
(_) => _
)
)
)
)
);
}