Skip to content

Instantly share code, notes, and snippets.

@techomoro
Created October 6, 2021 10:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save techomoro/3f9ac51efc37132d60d2a29b3b327e22 to your computer and use it in GitHub Desktop.
Save techomoro/3f9ac51efc37132d60d2a29b3b327e22 to your computer and use it in GitHub Desktop.
// 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