Support for loading, deleting, tag joining, and
This commit is contained in:
30
src/app/store/comment/comment.effects.ts
Normal file
30
src/app/store/comment/comment.effects.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
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
|
||||
) { }
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user