2018-04-06 11:02:18 +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/map';
|
|
|
|
import 'rxjs/add/operator/take';
|
|
|
|
|
|
|
|
import { TargetService } from '../../service/target.service';
|
|
|
|
|
|
|
|
import {
|
2018-04-30 10:59:32 +00:00
|
|
|
Modify,
|
|
|
|
ModifySuccess,
|
|
|
|
ModifyFailure,
|
2018-04-06 11:02:18 +00:00
|
|
|
ActionType,
|
2018-04-30 10:59:32 +00:00
|
|
|
} from './modify.action';
|
2018-04-06 11:02:18 +00:00
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class Effects {
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
private actions$: Actions,
|
|
|
|
private targetService: TargetService,
|
|
|
|
private router: Router
|
|
|
|
) { }
|
|
|
|
|
|
|
|
@Effect()
|
2018-04-30 10:59:32 +00:00
|
|
|
modify$: Observable<Action> = this.actions$
|
|
|
|
.ofType(ActionType.Modify)
|
|
|
|
.map((action: Modify) => action.payload)
|
|
|
|
.exhaustMap(target =>
|
|
|
|
this.targetService.modify(target)
|
|
|
|
.map(targets => new ModifySuccess(targets))
|
|
|
|
.catch(error => of(new ModifyFailure(error)))
|
2018-04-06 11:02:18 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
}
|