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 { MetaCrawler, MetaCrawlerInputItem } from '@overflow/commons-typescript/model/meta';
|
|
|
|
|
2018-05-29 10:17:16 +00:00
|
|
|
import { MetaCrawlerInputItemService } from '../../../service/meta-crawler-input-item.service';
|
|
|
|
|
|
|
|
import {
|
|
|
|
ReadAllByMetaCrawler,
|
|
|
|
ReadAllByMetaCrawlerSuccess,
|
|
|
|
ReadAllByMetaCrawlerFailure,
|
|
|
|
ActionType,
|
|
|
|
} from './meta-crawler-input-item.action';
|
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class Effects {
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
private actions$: Actions,
|
|
|
|
private metaCrawlerInputItemService: MetaCrawlerInputItemService,
|
|
|
|
) { }
|
|
|
|
|
|
|
|
@Effect()
|
|
|
|
readAllByMetaCrawler$ = this.actions$.pipe(
|
|
|
|
ofType(ActionType.ReadAllByMetaCrawler),
|
|
|
|
map((action: ReadAllByMetaCrawler) => action.payload),
|
|
|
|
exhaustMap((metaCrawler: MetaCrawler) =>
|
|
|
|
this.metaCrawlerInputItemService
|
|
|
|
.readAllByMetaCrawler(metaCrawler)
|
|
|
|
.pipe(
|
|
|
|
map((result: MetaCrawlerInputItem[]) => {
|
|
|
|
return new ReadAllByMetaCrawlerSuccess(result);
|
|
|
|
}),
|
|
|
|
catchError(error => of(new ReadAllByMetaCrawlerFailure(error)))
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|