// Saga watcher
const watchFetchCart = createAsyncPagingWatcher({
actionPrefix: 'FETCH_PRODUCTS',
getPromises: (state, action) => [() => api.fetchProduct({ limit: action.payload.limit, offset: action.payload.firstOffset ? 0 : state.products.offset })]
});
function* rootSaga() {
yield all([
watchFetchCart()
]);
}
// Reducer
const products = createAsyncPagingReducer('FETCH_PRODUCTS');
Create a saga watcher. It works closely with the function createAsyncReducer creating a reducer with the same matched prefix action type
// Saga watcher
const watchFetchCart = createAsyncWatcher({
actionPrefix: 'FETCH_CART',
getPromises: () => [() => api.fetchCart()]
});
function* rootSaga() {
yield all([
watchFetchCart()
]);
}
// Reducer
const carts = createAsyncReducer('FETCH_CART')
Function for helping running async task having status pending, success, fail and cancel
// Example
function* saga() {
const task = yield fork(runAsync, {
getPromises: () => [() => api.fetchCart()],
statuses: {
pending: ActionTypeMaker.PENDING('FETCH_CART'),
success: ActionTypeMaker.SUCCESS('FETCH_CART'),
fail: ActionTypeMaker.FAIL('FETCH_CART'),
reset: ActionTypeMaker.RESET('FETCH_CART'),
cancel: ActionTypeMaker.CANCEL('FETCH_CART'),
}
});
// Wait if success or fail
yield take([ActionTypeMaker.SUCCESS('FETCH_CART'), ActionTypeMaker.FAIL('FETCH_CART')])
}
Generated using TypeDoc
Create a saga watcher. It works closely with the function createAsyncPagingReducer creating a reducer with the same matched prefix action type