Skip to content

Instantly share code, notes, and snippets.

@emilong
Last active April 6, 2016 23:15
Show Gist options
  • Save emilong/c1e108a97558ab627fd908255e90e105 to your computer and use it in GitHub Desktop.
Save emilong/c1e108a97558ab627fd908255e90e105 to your computer and use it in GitHub Desktop.
import { takeLatest } from 'redux-saga'
import { call, put } from 'redux-saga/effects'
function* fetchThing(action) {
try {
const thing = yield call(fetch, `https://api.example.com/things/${action.payload.thingId}`);
yield put({ type: "THING_RECEIVED", thing });
} catch(err) {
yield put({ type: "THING_GETTING_FAILED", message: err.message});
}
}
export function* thingRequestSaga() {
yield* takeLatest("THING_GET_REQUESTED", fetchThing);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment