From df832c68503d445ceaa3f0a4ef72e26537dfa21f Mon Sep 17 00:00:00 2001 From: thomas Date: Fri, 16 Dec 2022 14:26:14 +0100 Subject: [PATCH] fix(challengeCrud): error in dev --- apps/crud/src/app/app.store.ts | 58 ---------------------------------- 1 file changed, 58 deletions(-) delete mode 100644 apps/crud/src/app/app.store.ts diff --git a/apps/crud/src/app/app.store.ts b/apps/crud/src/app/app.store.ts deleted file mode 100644 index c875718..0000000 --- a/apps/crud/src/app/app.store.ts +++ /dev/null @@ -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( - pipe( - tap(() => this.patchState({ loading: true })), - switchMap(() => - this.todoService.getAllTodo().pipe( - tapResponse( - (todos) => this.patchState({ todos, loading: false }), - (_) => _ - ) - ) - ) - ) - ); - - readonly updateTodo = this.effect( - pipe( - tap(() => this.patchState({ loading: true })), - switchMap((id) => - this.todoService.update(id).pipe( - tapResponse( - (todo) => this.updateTodos(todo), - (_) => _ - ) - ) - ) - ) - ); -}