Created
August 31, 2018 12:22
-
-
Save datvtwkm/fab9e67e0d5496904028cd38625630ec to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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