import { catchError, map, switchMap } from 'rxjs/operators'; import { combineEpics, ofType } from 'redux-observable'; import { FAQ, getAllFailure, getAllRequest, getAllSuccess } from './faq.actions'; import { ENTERED_FAQ_PAGE } from 'app/common/store/router/router.constants'; import { PretypedEpic } from 'app/common/store/store.types'; export const enteredFaqPageEpic: PretypedEpic = (action$) => { return action$.pipe( ofType(ENTERED_FAQ_PAGE), map(() => [ getAllRequest() ]) ); }; export const getAllEpic: PretypedEpic = (action$, _, { faqService }) => { return action$.pipe( ofType(FAQ.GET_ALL_REQUEST), switchMap(() => { return faqService.getFaq().pipe( map((faq) => [ getAllSuccess(faq), ]), catchError(() => [ getAllFailure(), ]), ); }), ); }; const faqEpic = combineEpics(enteredFaqPageEpic, getAllEpic); export { faqEpic };