Files
freeCodeCamp/common/app/routes/map/redux/fetch-challenges-saga.js

18 lines
611 B
JavaScript
Raw Normal View History

2016-03-21 15:39:45 -07:00
import { Observable } from 'rx';
import { fetchChallenges } from './types';
import { fetchChallengesCompleted } from './actions';
import { handleError } from '../../../redux/types';
2016-04-24 21:54:48 -07:00
export default function fetchChallengesSaga(action$, getState, { services }) {
return action$
.filter(action => action.type === fetchChallenges)
.flatMap(() => {
return services.readService$({ service: 'map' })
.map(({ entities, result } = {}) => {
return fetchChallengesCompleted(entities, result);
})
.catch(error => Observable.just({ type: handleError, error }));
});
}