@kkt/plugin-pro-rematch
TypeScript icon, indicating that this package has built-in type declarations

1.1.5 • Public • Published

状态管理

kktp内置插件,是以@rematch/core包为基础进行自动收集状态管理。使用此插件需要安装@rematch/core@rematch/loading包。

参数

export interface ModelspluginProps {
  /**自动生成文件目录名称*/
  cacheDirName?: string;
}

models ts 实例

// src/models/demo.ts
export interface DemoState {
  test?: string;
}

const demo = {
  name: 'demo',
  state: {
    test: '测试State',
  },
  reducers: {
    updateState: (state: DemoState, payload: DemoState): DemoState => ({
      ...state,
      ...payload,
    }),
  },
  effects: (dispatch) => {
    const { demo } = dispatch;
    return {
      async verify() {
        demo.updateState({ test: '测试22' });
      },
    }
  },
};
export default demo;


// src/pages/ceshi.tsx
import { RootState, useSelector, dispatch } from '@kkt/pro';
const Ceshi = () => {
  // 获取demo数据
  const store = useSelector((store: RootState) => store.demo);
  // Dispatch
  const dispatch = useDispatch<Dispatch>();

  const click = () => {
    dispatch({
      type: 'demo/verify',
      payload: {}
    })
  }
  return <div />
}
export default Ceshi;

自动收集文件引入

  1. 约定src/**/models/**/*.(js|ts)文件

kktp配置文件

// .kktprc.ts
export default {
  // ...
  initModel:true,
}

Contributors

License

Licensed under the MIT License.

Package Sidebar

Install

npm i @kkt/plugin-pro-rematch

Weekly Downloads

12

Version

1.1.5

License

MIT

Unpacked Size

40.1 kB

Total Files

17

Last publish

Collaborators

  • uiwjs
  • wcjiang