Last active
June 12, 2017 12:34
-
-
Save rgommezz/ddd50fbf22e303854813d4af0834582f to your computer and use it in GitHub Desktop.
This file contains hidden or 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 NetInfo from 'react-native'; | |
| import { call, put, select, fork, takeEvery } from 'redux-saga'; | |
| import * as actions from './actions'; | |
| import api from './api'; | |
| function* fetchData({ payload }) { | |
| const isConnected = yield call([NetInfo, NetInfo.isConnected.fetch]); | |
| if (isConnected) { | |
| const accessToken = yield select(accessTokenSelector); | |
| try { | |
| const { data } = yield call(api.fetchData, accessToken, payload.params); | |
| yield put(actions.fetchDataSuccess(data)); | |
| } catch (error) { | |
| yield put(actions.fetchDataError({ | |
| errorType: 'server' | |
| })); | |
| } | |
| } else { | |
| yield put(actions.fetchDataError({ | |
| errorType: 'offline', | |
| })); | |
| } | |
| } | |
| export default function* watchFetchData() { | |
| yield fork(takeEvery, 'FETCH_DATA_REQUEST', fetchData); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment