member_webapp/src/packages/probe/store/remove/remove.effect.ts

50 lines
1.2 KiB
TypeScript
Raw Normal View History

2018-04-29 10:43:14 +00:00
import { Injectable } from '@angular/core';
import { Router } from '@angular/router';
import { Effect, Actions, ofType } from '@ngrx/effects';
import { Action } from '@ngrx/store';
import { Observable } from 'rxjs/Observable';
import { of } from 'rxjs/observable/of';
import 'rxjs/add/operator/catch';
import 'rxjs/add/operator/do';
import 'rxjs/add/operator/exhaustMap';
import 'rxjs/add/operator/switchMap';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/take';
import { RPCClientError } from '@loafer/ng-rpc/protocol';
import { Probe } from '../../model';
import { ProbeService } from '../../service/probe.service';
import {
Remove,
RemoveSuccess,
RemoveFailure,
ActionType
} from './remove.action';
@Injectable()
export class Effects {
constructor(
private actions$: Actions,
private probeService: ProbeService,
private router: Router
) { }
@Effect()
remove$: Observable<Action> = this.actions$
.ofType(ActionType.Remove)
.map((action: Remove) => action.payload)
.switchMap(payload => this.probeService.remove(payload.id))
.map(result => {
return new RemoveSuccess(result);
})
.catch((error: RPCClientError) => {
return of(new RemoveFailure(error));
});
}