53 lines
1.4 KiB
TypeScript
Raw Normal View History

2019-09-18 15:02:21 +09:00
import { Injectable } from '@angular/core';
import { Router } from '@angular/router';
import { Actions, ofType, createEffect } from '@ngrx/effects';
import { of } from 'rxjs';
import { catchError, exhaustMap, map, tap } from 'rxjs/operators';
import { PublicApiService } from '@ucap-webmessenger/api-public';
import { StatusCode } from '@ucap-webmessenger/api';
2019-09-19 10:40:16 +09:00
import { SessionStorageService } from '@ucap-webmessenger/web-storage';
import { fetch, fetchSuccess, fetchFailure } from './actions';
2019-09-18 15:02:21 +09:00
@Injectable()
export class Effects {
fetch$ = createEffect(() =>
this.actions$.pipe(
ofType(fetch),
map(action => action),
exhaustMap(req =>
2019-09-19 10:40:16 +09:00
this.publicApiService.versionInfo2(req).pipe(
2019-09-18 15:02:21 +09:00
map(res => {
if (res.statusCode === StatusCode.Success) {
2019-09-19 10:40:16 +09:00
console.log('fetchSuccess', res);
2019-09-18 15:02:21 +09:00
return fetchSuccess(res);
} else {
return fetchFailure({ error: 'Failed' });
}
}),
catchError(error => of(fetchFailure({ error })))
)
)
)
);
fetchSuccess$ = createEffect(
() =>
this.actions$.pipe(
ofType(fetchSuccess),
tap(params => {})
),
{ dispatch: false }
);
constructor(
private actions$: Actions,
private publicApiService: PublicApiService,
2019-09-19 10:40:16 +09:00
private sessionStorageService: SessionStorageService,
2019-09-18 15:02:21 +09:00
private router: Router
) {}
}