2018-05-29 10:17:16 +00:00
|
|
|
import { Injectable } from '@angular/core';
|
|
|
|
import { Effect, Actions, ofType } from '@ngrx/effects';
|
|
|
|
import { of } from 'rxjs';
|
|
|
|
import { catchError, exhaustMap, map, tap } from 'rxjs/operators';
|
|
|
|
|
2018-05-29 10:49:29 +00:00
|
|
|
import { MetaProbePackage, MetaProbeOs } from '@overflow/commons-typescript/model/meta';
|
|
|
|
|
2018-05-29 10:17:16 +00:00
|
|
|
import { MetaProbePackageService } from '../../../service/meta-probe-package.service';
|
|
|
|
|
|
|
|
import {
|
|
|
|
ReadAllByOs,
|
|
|
|
ReadAllByOsSuccess,
|
|
|
|
ReadAllByOsFailure,
|
|
|
|
ActionType,
|
|
|
|
} from './meta-probe-package.action';
|
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class Effects {
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
private actions$: Actions,
|
|
|
|
private metaProbePackageService: MetaProbePackageService,
|
|
|
|
) { }
|
|
|
|
|
|
|
|
@Effect()
|
|
|
|
readAllByOs$ = this.actions$.pipe(
|
|
|
|
ofType(ActionType.ReadAllByOs),
|
|
|
|
map((action: ReadAllByOs) => action.payload),
|
|
|
|
exhaustMap((metaProbeOs: MetaProbeOs) =>
|
|
|
|
this.metaProbePackageService
|
|
|
|
.readAllByOs(metaProbeOs)
|
|
|
|
.pipe(
|
|
|
|
map((result: MetaProbePackage[]) => {
|
|
|
|
return new ReadAllByOsSuccess(result);
|
|
|
|
}),
|
|
|
|
catchError(error => of(new ReadAllByOsFailure(error)))
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|