Created
October 6, 2021 10:18
-
-
Save techomoro/3f9ac51efc37132d60d2a29b3b327e22 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
// store/posts/saga.js | |
import { takeLatest, put, call } from "redux-saga/effects"; | |
import { GET_POSTS, GET_POST_DETAILS } from "./actionTypes"; | |
import { | |
getPostsSuccess, | |
getPostsFail, | |
getPostDetailsSuccess, | |
getPostDetailsFail, | |
} from "./actions"; | |
import { getPosts, getPostDetails } from "../../helpers/backend_helper"; | |
function* onGetPosts() { | |
try { | |
const response = yield call(getPosts); | |
yield put(getPostsSuccess(response)); | |
} catch (error) { | |
yield put(getPostsFail(error.response)); | |
} | |
} | |
function* onGetPostDetails({ payload: id }) { | |
try { | |
const response = yield call(getPostDetails, id); | |
yield put(getPostDetailsSuccess(response)); | |
} catch (error) { | |
yield put(getPostDetailsFail(error.response)); | |
} | |
} | |
function* CartSaga() { | |
yield takeLatest(GET_POSTS, onGetPosts); | |
yield takeLatest(GET_POST_DETAILS, onGetPostDetails); | |
} | |
export default CartSaga; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment