@ackee/redux-utils 中文文档教程
Redux Utilities
常用的 Redux 实用程序,包括:
- Reducer factories (
containerReducer
,resetReducer
,basicApiReducer
a more). - Generic API request action type and creator factories (
asyncType
,apiRequestActions
).
Table of contents
- Installing
- Configuration
- API References
- Action Type helpers
- Action Creator helpers
- Reducer factories
- Selectors for API reducers
- Utilities
Installing
使用 yarn:
$ yarn add @ackee/redux-utils
使用 npm:
$ npm i -S @ackee/redux-utils
Configuration (optional)
可用选项:
- Set initial reducer state globally.
- Set custom logger.
import { configure } from '@ackee/redux-utils';
// Defaults:
configure({
// Pass any object with error, warn and info methods.
logger: console,
containerReducer: reducerConfig => reducerConfig,
basicApiReducer: reducerConfig => reducerConfig,
paginationApiReducer: reducerConfig => reducerConfig,
infiniteListApiReducer: reducerConfig => reducerConfig,
});
Change reducer initial state globally
import { configure } from '@ackee/redux-utils';
configure({
// ...
basicApiReducer: ({ initialState, ...rest }) => {
return {
...rest,
initialState: {
...initialState,
// Override default error initial value:
error: null,
},
};
},
});
Redux Utilities
Common Redux utilities, including:
- Reducer factories (
containerReducer
,resetReducer
,basicApiReducer
a more). - Generic API request action type and creator factories (
asyncType
,apiRequestActions
).
Table of contents
- Installing
- Configuration
- API References
- Action Type helpers
- Action Creator helpers
- Reducer factories
- Selectors for API reducers
- Utilities
Installing
Using yarn:
$ yarn add @ackee/redux-utils
Using npm:
$ npm i -S @ackee/redux-utils
Configuration (optional)
Available options:
- Set initial reducer state globally.
- Set custom logger.
import { configure } from '@ackee/redux-utils';
// Defaults:
configure({
// Pass any object with error, warn and info methods.
logger: console,
containerReducer: reducerConfig => reducerConfig,
basicApiReducer: reducerConfig => reducerConfig,
paginationApiReducer: reducerConfig => reducerConfig,
infiniteListApiReducer: reducerConfig => reducerConfig,
});
Change reducer initial state globally
import { configure } from '@ackee/redux-utils';
configure({
// ...
basicApiReducer: ({ initialState, ...rest }) => {
return {
...rest,
initialState: {
...initialState,
// Override default error initial value:
error: null,
},
};
},
});