1.3.6 • Published 6 years ago

ocean-utils v1.3.6

Weekly downloads
2
License
ISC
Repository
-
Last release
6 years ago

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

6 years ago

1.3.5

6 years ago

1.3.4

6 years ago

1.3.3

6 years ago

1.3.2

6 years ago

1.3.1

6 years ago

1.3.0

6 years ago

1.2.19

6 years ago

1.2.18

6 years ago

1.2.17

6 years ago

1.2.16

6 years ago

1.2.15

6 years ago

1.2.14

6 years ago

1.2.13

6 years ago

1.2.12

6 years ago

1.2.11

6 years ago

1.2.10

6 years ago

1.2.9

6 years ago

1.2.8

6 years ago

1.2.7

6 years ago

1.2.6

6 years ago

1.2.5

6 years ago

1.2.4

6 years ago

1.2.3

6 years ago

1.2.2

6 years ago

1.2.1

6 years ago

1.2.0

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.16

6 years ago

1.0.15

6 years ago

1.0.14

6 years ago

1.0.13

6 years ago

1.0.12

6 years ago

1.0.11

6 years ago

1.0.10

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago