Files
freeCodeCamp/common/app/routes/Jobs/redux/save-job-saga.js

33 lines
764 B
JavaScript
Raw Normal View History

import { push } from 'react-router-redux';
2016-03-02 16:33:44 -08:00
import { Observable } from 'rx';
2016-02-25 18:30:10 -08:00
2016-03-02 16:33:44 -08:00
import { saveCompleted } from './actions';
2016-02-25 18:30:10 -08:00
import { saveJob } from './types';
import { handleError } from '../../../redux/types';
export default ({ services }) => ({ dispatch }) => next => {
return function saveJobSaga(action) {
2016-03-02 16:33:44 -08:00
const result = next(action);
2016-02-25 18:30:10 -08:00
if (action.type !== saveJob) {
2016-03-02 16:33:44 -08:00
return result;
2016-02-25 18:30:10 -08:00
}
const { payload: job } = action;
return services.createService$({
service: 'jobs',
params: { job }
})
.retry(3)
.flatMap(job => Observable.of(
2016-03-02 16:33:44 -08:00
saveCompleted(job),
push('/jobs/new/check-out')
))
2016-02-25 18:30:10 -08:00
.catch(error => Observable.just({
type: handleError,
error
}))
.doOnNext(dispatch);
};
};