2018-04-27 07:31:27 +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';
|
|
|
|
|
2018-05-24 06:44:13 +00:00
|
|
|
import { RPCClientError } from '@loafer/ng-rpc';
|
2018-04-27 07:31:27 +00:00
|
|
|
|
2018-05-02 08:09:39 +00:00
|
|
|
import { Probe } from '@overflow/commons-typescript/model/probe';
|
2018-04-27 07:31:27 +00:00
|
|
|
import { ProbeService } from '../../service/probe.service';
|
|
|
|
|
|
|
|
import {
|
|
|
|
Modify,
|
2018-05-02 03:59:45 +00:00
|
|
|
ModifyDisplayName,
|
2018-04-27 07:31:27 +00:00
|
|
|
ModifySuccess,
|
|
|
|
ModifyFailure,
|
|
|
|
ActionType
|
|
|
|
} from './modify.action';
|
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class Effects {
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
private actions$: Actions,
|
|
|
|
private probeService: ProbeService,
|
|
|
|
private router: Router
|
|
|
|
) { }
|
|
|
|
|
|
|
|
@Effect()
|
|
|
|
modify$: Observable<Action> = this.actions$
|
|
|
|
.ofType(ActionType.Modify)
|
|
|
|
.map((action: Modify) => action.payload)
|
|
|
|
.switchMap(payload => this.probeService.modify(payload))
|
|
|
|
.map(probe => {
|
|
|
|
return new ModifySuccess(probe);
|
|
|
|
})
|
|
|
|
.catch((error: RPCClientError) => {
|
|
|
|
return of(new ModifyFailure(error));
|
|
|
|
});
|
2018-05-02 03:59:45 +00:00
|
|
|
|
|
|
|
@Effect()
|
|
|
|
modifyDisplayName$: Observable<Action> = this.actions$
|
|
|
|
.ofType(ActionType.ModifyDisplayName)
|
|
|
|
.map((action: ModifyDisplayName) => action.payload)
|
|
|
|
.switchMap(payload => this.probeService.modifyDisplayName(payload.id, payload.displayName))
|
|
|
|
.map(probe => {
|
|
|
|
return new ModifySuccess(probe);
|
|
|
|
})
|
|
|
|
.catch((error: RPCClientError) => {
|
|
|
|
return of(new ModifyFailure(error));
|
|
|
|
});
|
2018-04-27 07:31:27 +00:00
|
|
|
}
|