1
0
This repository has been archived on 2025-11-02. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
comment-system/src/app/store/comment/comment.effects.ts

31 lines
803 B
TypeScript

import { Injectable } from '@angular/core';
import { Actions, createEffect, ofType } from '@ngrx/effects';
import { of } from 'rxjs';
import { map, switchMap, catchError } from 'rxjs/operators';
import { CommentService } from './comment.service';
import * as CommentActions from './comment.actions';
@Injectable()
export class CommentEffects {
loadComments$ = createEffect(() =>
this.actions$.pipe(
ofType(CommentActions.loadComments),
switchMap(_ =>
this.api.getAll().pipe(
map(data => CommentActions.loadCommentsSuccess({ comments: data as any })), // debug type issue here
catchError(_ => of(CommentActions.loadCommentsFailure()))
)
)
)
);
constructor(
private api: CommentService,
private actions$: Actions
) { }
}