import { catchError, map } from 'rxjs/operators'; import { ProjectActionTypes } from './project.action.type'; import { ProjectActionUnion, DeleteProjectActionSuccess, DeleteProjectActionError } from './project.action'; import { Observable, mergeMap, of } from 'rxjs'; import { ProjectService } from './../../shared/services/project.service'; import { Actions, createEffect, ofType } from '@ngrx/effects'; import { Injectable } from "@angular/core"; @Injectable() export class ProjectDeleteEffect { constructor(private projectActions: Actions, private projectService: ProjectService){} //delete project effect deleteProjectEffect : Observable = createEffect( ()=> this.projectActions.pipe( ofType(ProjectActionTypes.DELETE_PROJECT), mergeMap((action: ProjectActionUnion)=>{ return this.projectService.deleteProject(action.payload.projectID).pipe( map( ()=> new DeleteProjectActionSuccess(action.payload)), catchError(err => of(new DeleteProjectActionError(err))) ) }) ) ) }