import { put, call } from 'redux-saga/effects'; // resuable fetch Subroutine // entity : user | repo | starred | stargazers // apiFn : api.fetchUser | api.fetchRepo | ... // id : login | fullName // url : next page url. If not provided will use pass it to apiFn export function* fetchEntity(entity, apiFn, params) { yield put(entity.request(params)); const { response, error } = yield call(apiFn, params); if (response) { yield put(entity.success({ response, params })); } else { yield put(entity.failure({ error, params })); } }