Skip to content

Instantly share code, notes, and snippets.

@datvtwkm
Created August 31, 2018 12:22
Show Gist options
  • Save datvtwkm/fab9e67e0d5496904028cd38625630ec to your computer and use it in GitHub Desktop.
Save datvtwkm/fab9e67e0d5496904028cd38625630ec to your computer and use it in GitHub Desktop.
import {
call,
put,
race,
select,
take,
takeLatest
} from 'redux-saga/effects';
import actionGenerators from '../../../creators/actionGenerators';
import api from './api';
const {
start, cancel, succeed, fail
} = actionGenerators.auth.login;
function* login() {
try {
let data = yield call(api);
yield put(succeed(data));
} catch (e) {
return yield put(fail(e));
}
}
const loginSaga = function* () {
yield takeLatest([start], function* (...args) {
yield race({
task: call(login, ...args),
cancel: take(cancel)
});
});
};
export default loginSaga;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment