member_webapp/@overflow/meta/store/entity/meta-member-status/meta-member-status.effect.ts
crusader 10e14d5edb ing
2018-05-29 19:17:16 +09:00

39 lines
984 B
TypeScript

import { Injectable } from '@angular/core';
import { Effect, Actions, ofType } from '@ngrx/effects';
import { of } from 'rxjs';
import { catchError, exhaustMap, map, tap } from 'rxjs/operators';
import { MetaMemberStatusService } from '../../../service/meta-member-status.service';
import {
ReadAll,
ReadAllSuccess,
ReadAllFailure,
ActionType,
} from './meta-member-status.action';
import { MetaMemberStatus } from '@overflow/commons-typescript/model/meta';
@Injectable()
export class Effects {
constructor(
private actions$: Actions,
private metaMemberStatusService: MetaMemberStatusService,
) { }
@Effect()
readAll$ = this.actions$.pipe(
ofType(ActionType.ReadAll),
exhaustMap(() =>
this.metaMemberStatusService
.readAll()
.pipe(
map((result: MetaMemberStatus[]) => {
return new ReadAllSuccess(result);
}),
catchError(error => of(new ReadAllFailure(error)))
)
)
);
}