Main action type
Initial state in form of { data: Array<T extends { id: any }>, offset: 0, pending: boolean, error: any, hasMore: boolean }
// Example
const carts = createAsyncPagingReducer('FETCH_CARTS');
Help creating async paging reducers with less lines of code
instance object that its properties representing reducer names and the property values representing action types
instance of object that its properies points to created async reducers
Example
const product = createAsyncReducerGroup({
productList: ['FETCH_PRODUCTS', { data: [] }], // set initial state with empty array for property data
cartList: 'FETCH_CARTS',
});
const reducers = combineReducers({
...product,
});
Create a reducer that working with work related steps of state changes like: PENDING
=> SUCCESS
or FAIL
.
This function works closely with saga function createAsyncApiWatcher
Motivation
// Old way
const profile = (state = { data: null, pending: false, error: null }, action) => {
switch(action.type) {
case 'FETCH_USER_PROFILE_PENDING':
return { pending: true };
case 'FETCH_USER_PROFILE_SUCCESS':
return { pending: false, data: action.payload };
case 'FETCH_USER_PROFILE_FAIL':
return { pending: false, error: action.payload };
default:
return state;
}
}
// New way
const profile = createAsyncReducer('FETCH_USER_PROFILE');
Main action type
Reducer function that handle other custom action types
Initial state in form of { data: any, pending: boolean, error: any }
// Example
const profile = createAsyncReducer('FETCH_USER_PROFILE');
Tell if a reducer has error
Tell if a reducer is pending for any work
Help creating async reducers with less lines of code
instance object that its properties representing reducer names and the property values representing action types
instance of object that its properies points to created async reducers
Example
const product = createAsyncReducerGroup({
productList: 'FETCH_PRODUCTS',
productDetail: ['FETCH_PRODUCT_DETAIL', { data: {} }], // set initial state with instance object for property data
cartList: 'FETCH_CARTS',
});
const reducers = combineReducers({
...product,
});
Create a batch of reducer object that each property representing nested reducers
const reducers = createReducerBatch({
mute: ['SET_MUTE', false],
profile: ['SET_PROFILE', { name: '', gender: '' }]
});
// You will get a reducer like the following one
reducers = {
mute: function (state = false, action) { ... },
profile: function (state = { name: '', gender: '' }, action) { ... }
}
Help create a reducer that you can manage how state should be changed in nested reducers
Generated using TypeDoc
Create a reducer that working with work related steps of state changes like:
PENDING
=>SUCCESS
orFAIL
. Moreover main use is to target work related to pagination (limit
andoffset
) with server request, database and so on. This function works closely with saga function createAsyncPagingApiWatcherMotivation