Skip to content

Commit 619f38d

Browse files
committed
added redux_sagas to project
1 parent 2b8f972 commit 619f38d

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

src/sagas/productsSagas.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import {
2+
FETCH_PRODUCTS,
3+
FETCH_PRODUCTS_SUCCESS,
4+
FETCH_PRODUCTS_FAILED,
5+
} from '../actions';
6+
import { put, call, takeLatest } from 'redux-saga/effects';
7+
import { getProducts } from '../services';
8+
9+
export function* fetchProducts() {
10+
try {
11+
const receivedProducts = yield call(getProducts);
12+
yield put({
13+
type: FETCH_PRODUCTS_SUCCESS,
14+
receivedProducts: receivedProducts.data,
15+
});
16+
} catch (error) {
17+
yield put({ type: FETCH_PRODUCTS_FAILED, error });
18+
}
19+
}
20+
21+
export function* watchFetchProducts() {
22+
yield takeLatest(FETCH_PRODUCTS, fetchProducts);
23+
}

src/sagas/rootSaga.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { all } from 'redux-saga/effects';
2+
import { watchFetchProducts } from './productsSagas';
3+
4+
export default function* rootSaga() {
5+
yield all([watchFetchProducts()]);
6+
}

0 commit comments

Comments
 (0)