Slide 75
Slide 75 text
export const TodoStore = signalStore(
{ providedIn: 'root' },
withState({ /* state goes here */ ),
withMethods((store, todoService = inject(TodoService)) => ({
loadAllTodos: rxMethod(
switchMap(() => {
patchState(store, {loading: true});
return todoService.getItems().pipe(
tapResponse({
next: (items) => patchState(store, {items}),
error: console.error,
finalize: () => patchState(store, {loading: false}),
})
);
})
),
}))
);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
loadAllTodos: rxMethod(
switchMap(() => {
patchState(store, {loading: true});
return todoService.getItems().pipe(
tapResponse({
next: (items) => patchState(store, {items}),
error: console.error,
finalize: () => patchState(store, {loading: false}),
})
);
})
),
export const TodoStore = signalStore(
1
{ providedIn: 'root' },
2
withState({ /* state goes here */ ),
3
withMethods((store, todoService = inject(TodoService)) => ({
4
5
6
7
8
9
10
11
12
13
14
15
16
17
}))
18
);
19
patchState(store, {loading: true});
export const TodoStore = signalStore(
1
{ providedIn: 'root' },
2
withState({ /* state goes here */ ),
3
withMethods((store, todoService = inject(TodoService)) => ({
4
loadAllTodos: rxMethod(
5
switchMap(() => {
6
7
8
return todoService.getItems().pipe(
9
tapResponse({
10
next: (items) => patchState(store, {items}),
11
error: console.error,
12
finalize: () => patchState(store, {loading: false}),
13
})
14
);
15
})
16
),
17
}))
18
);
19
return todoService.getItems().pipe(
tapResponse({
next: (items) => patchState(store, {items}),
error: console.error,
finalize: () => patchState(store, {loading: false}),
})
);
export const TodoStore = signalStore(
1
{ providedIn: 'root' },
2
withState({ /* state goes here */ ),
3
withMethods((store, todoService = inject(TodoService)) => ({
4
loadAllTodos: rxMethod(
5
switchMap(() => {
6
patchState(store, {loading: true});
7
8
9
10
11
12
13
14
15
})
16
),
17
}))
18
);
19
tapResponse({
next: (items) => patchState(store, {items}),
error: console.error,
finalize: () => patchState(store, {loading: false}),
})
export const TodoStore = signalStore(
1
{ providedIn: 'root' },
2
withState({ /* state goes here */ ),
3
withMethods((store, todoService = inject(TodoService)) => ({
4
loadAllTodos: rxMethod(
5
switchMap(() => {
6
patchState(store, {loading: true});
7
8
return todoService.getItems().pipe(
9
10
11
12
13
14
);
15
})
16
),
17
}))
18
);
19