2018-04-19 10:26:39 +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';
|
|
|
|
|
2018-05-24 06:44:13 +00:00
|
|
|
import { RPCClientError } from '@loafer/ng-rpc';
|
2018-04-19 10:26:39 +00:00
|
|
|
|
2018-05-02 08:09:39 +00:00
|
|
|
import { Infra } from '@overflow/commons-typescript/model/infra';
|
2018-04-19 10:26:39 +00:00
|
|
|
|
|
|
|
import {
|
|
|
|
Read,
|
|
|
|
ReadSuccess,
|
|
|
|
ReadFailure,
|
|
|
|
ActionType,
|
|
|
|
} from './detail.action';
|
|
|
|
import { InfraService } from '../../service/infra.service';
|
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class Effects {
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
private actions$: Actions,
|
|
|
|
private infraService: InfraService,
|
|
|
|
private router: Router
|
|
|
|
) { }
|
|
|
|
|
|
|
|
@Effect()
|
|
|
|
read$: Observable<Action> = this.actions$
|
|
|
|
.ofType(ActionType.Read)
|
|
|
|
.map((action: Read) => action.payload)
|
|
|
|
.switchMap(payload => this.infraService.read(payload.id))
|
|
|
|
.map(infra => {
|
|
|
|
return new ReadSuccess(infra);
|
|
|
|
})
|
|
|
|
.catch((error: RPCClientError) => {
|
|
|
|
return of(new ReadFailure(error));
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|