Last active
December 2, 2018 13:11
-
-
Save smks/e60005fe26f2f39202c5ce2dd6a9cf64 to your computer and use it in GitHub Desktop.
Saga for people.js
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 { call, put, takeEvery } from 'redux-saga/effects'; | |
import API from '../services/api'; | |
import { getPeople } from '../actions'; | |
export function* callPeopleService() { | |
return yield call(API.getPeople); | |
} | |
export function* getPeopleRequest() { | |
try { | |
const { data } = yield call(callPeopleService); | |
yield put( | |
getPeople.success({ | |
people: data, | |
}), | |
); | |
} catch (error) { | |
yield put(getPeople.failure(error.message)); | |
} | |
} | |
export default function* peopleSaga() { | |
yield takeEvery(getPeople.REQUEST, getPeopleRequest); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment