Skip to content

Instantly share code, notes, and snippets.

@Djuki
Last active March 28, 2020 10:57
Show Gist options
  • Save Djuki/26ce196615004a53ed3fce6f533996bb to your computer and use it in GitHub Desktop.
Save Djuki/26ce196615004a53ed3fce6f533996bb to your computer and use it in GitHub Desktop.
import { FETCH_MORE_BRANCHES, successFetchBranches } from '../actions';
import { ofType } from 'redux-observable';
import { EMPTY, of } from 'rxjs';
import { ajax } from 'rxjs/ajax';
import { mergeMap, map, catchError } from 'rxjs/operators';
import tokenHeader from '../../common/helpers/token';
import { showAlertBox } from '../../common/layout';
const fetchLoadMoreBranchesEpic = action$ => {
return action$.pipe(
ofType(FETCH_MORE_BRANCHES),
mergeMap(({ identityId, nextPage }) => {
if (nextPage === false) {
return EMPTY;
}
return ajax.post(`/app/auto/repos/branches/${identityId}`, { nextPage }, tokenHeader()).pipe(
map(data => successFetchBranches(data.response.branches, data.response.nextPage)),
catchError(error => of(showAlertBox('danger', error.response.message)))
);
})
);
};
export default fetchLoadMoreBranchesEpic;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment