1.3.6 • Published 7 years ago
ocean-utils v1.3.6
storeHelper
- 生成store,env要求development/production
examples:
import { storeHelper } from 'ocean-utils';
export default storeHelper(process.env.NODE_ENV).configEmptyStore({});fetch
- 对axios的封装
- import { fetch } from 'ocean-utils'
- fetch.axios 与 axios 一致
- http.setRequestInterceptor(successFn, errorFn)、http.setResponseInterceptor(successFn, errorFn)可以设置拦截器,建议在项目入口设置一次就可以
- example:
fetch.setResponseInterceptor(
  res => {
    if (res.data.code !== 1) {
      throw new Error(res);
    } else {
      return res.data.data;
    }
  },
  error => {
    throw Error(error);
  }
)helper
helper/actionGenerator
- 生成actionType对象 examples:
export const ACTIVITY_LIST = actionGenerator('ACTIVITY_LIST');get:
{
  ACTION: 'ACTIVITY_LIST',
  SUCCESS: 'ACTIVITY_LIST_SUCCESS',
  FAILED: 'ACTIVITY_LIST_FAILED'
}sagaHelper
- 生成saga
function createSaga(configs, actionType)- configs是数组,包含promise和payload,promise是要异步执行的方法。payload时得到response以后adapter。promise.all得到了返回会依次作为入参传给payload方法。 
- actionType是在成功/失败以后触发的事件类型 
examples:
const login = sagaHelper.createSaga([{
  promise: authService.profile,
  payload: payload => ({profile: payload}),
}], PROFILE);- 同步逻辑 examples:
const login = sagaHelper.createSyncSaga(PROFILE);message 简单的事件队列,多用于child app之间通讯
message/MsgRegister 注册事件
examples:
MsgRegister('EVENT:TOGGLE_MENU', this.toggleMenu);message/MsgUnregister 取消注册
MsgUnregister('EVENT:TOGGLE_MENU', this.toggleMenu);message/MsgTrigger 触发事件
MsgTrigger('EVENT:TOGGLE_MENU');Lazyload
import { Lazyload } from 'ocean-utils';
const createComponent = (component) => {
  return () => {
    const AsyncComponent = (
      <Lazyload load={component}>
        {
          (Async) => {
            return Async ? <Async /> : <Loading />;
          }
        }
      </Lazyload>
    );
    return AsyncComponent;
  };
};
<Route path="/solution/result/:id" component={createComponent(Solution)} exact />1.3.6
7 years ago
1.3.5
7 years ago
1.3.4
7 years ago
1.3.3
7 years ago
1.3.2
7 years ago
1.3.1
7 years ago
1.3.0
7 years ago
1.2.19
7 years ago
1.2.18
7 years ago
1.2.17
7 years ago
1.2.16
7 years ago
1.2.15
7 years ago
1.2.14
7 years ago
1.2.13
7 years ago
1.2.12
7 years ago
1.2.11
7 years ago
1.2.10
7 years ago
1.2.9
7 years ago
1.2.8
8 years ago
1.2.7
8 years ago
1.2.6
8 years ago
1.2.5
8 years ago
1.2.4
8 years ago
1.2.3
8 years ago
1.2.2
8 years ago
1.2.1
8 years ago
1.2.0
8 years ago
1.1.3
8 years ago
1.1.2
8 years ago
1.1.1
8 years ago
1.1.0
8 years ago
1.0.16
8 years ago
1.0.15
8 years ago
1.0.14
8 years ago
1.0.13
8 years ago
1.0.12
8 years ago
1.0.11
8 years ago
1.0.10
8 years ago
1.0.9
8 years ago
1.0.8
8 years ago
1.0.7
8 years ago
1.0.6
8 years ago
1.0.5
8 years ago
1.0.4
8 years ago
1.0.3
8 years ago
1.0.2
8 years ago
1.0.1
8 years ago
1.0.0
8 years ago