Files
freeCodeCamp/common/app/routes/challenges/redux/next-challenge-saga.js

24 lines
798 B
JavaScript
Raw Normal View History

2016-06-09 16:02:51 -07:00
import { Observable } from 'rx';
import { push } from 'react-router-redux';
import { moveToNextChallenge } from './types';
import { getNextChallenge } from '../utils';
import { updateCurrentChallenge } from './actions';
// import { createErrorObservable, makeToast } from '../../../redux/actions';
export default function nextChallengeSaga(actions$, getState) {
return actions$
.filter(({ type }) => type === moveToNextChallenge)
.flatMap(() => {
const state = getState();
const nextChallenge = getNextChallenge(
state.challengesApp.challenge,
state.entities,
state.challengesApp.superBlocks
);
return Observable.of(
updateCurrentChallenge(nextChallenge),
push(`/challenges/${nextChallenge.dashedName}`)
);
});
}