Files
freeCodeCamp/api-server/common/app/Map/redux/fetch-map-ui-epic.js

39 lines
832 B
JavaScript
Raw Normal View History

import { ofType } from 'redux-epic';
import debug from 'debug';
import {
types as appTypes,
2018-05-15 06:12:05 +01:00
createErrorObservable
} from '../../redux';
import { types, fetchMapUiComplete } from './';
import { shapeChallenges } from '../../redux/utils';
const isDev = debug.enabled('fcc:*');
export default function fetchMapUiEpic(
actions,
2018-05-15 06:12:05 +01:00
_,
{ services }
) {
return actions::ofType(
appTypes.appMounted,
types.fetchMapUi.start
)
.flatMapLatest(() => {
const options = {
service: 'map-ui'
};
return services.readService$(options)
.retry(3)
.map(({ entities, ...res }) => ({
entities: shapeChallenges(
entities,
isDev
),
...res
}))
.map(fetchMapUiComplete)
.catch(createErrorObservable);
});
}