2.0.1 • Published 2 years ago

perkz v2.0.1

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

perkz

第一步
// 数据文件
import {Dispatch, MapRoute, StoreState} from "perkz";
import {connect} from "react-redux";


export type State = {
  name: string;
}

// 数据源
export const state = {
   namespace: "main" ,
   state: {
     name: "",
   },
   reducers: {
      init(state: StoreState) {
        return {...state};
      }
   }
}

function mapState(state: { main: State }) {
  return {
    ...state.main,
  };
}

// 数据更改
function mapDispatch(dispatch: Dispatch, params: MapRoute) {
  return {
    init() {
      dispatch({type: `main/init`});
      dispatch({type: `main/set/name`, name: ""});
      dispatch({type: `main/setState`, state: {name: ""}});
    },
  };
}

export interface IProps extends ReturnType<typeof mapDispatch>,
  ReturnType<typeof mapState> {
  [key: string]: any;
}

export default connect(mapState, mapDispatch);
第二步
// store 文件 存放数据源
import {createStores} from "perkz";
import {state as main}  from "@/store/main"
export default createStores({
  main,
})
第三步
import * as React from "react";
import {IReactHooksComponent} from "perkz";
import store, {IProps} from "@/store/main";

const Main: IReactHooksComponent<IProps> = (props) => {

  return <>{props.childrenRouter()}</>
};
export default store(Main);
第四步
// 路由配置文件
const routes = [
  {
    path: "/",
    Component: require("@/pages").default,
    redirect: "pc",
    name: "首页",
    children: [
      {
        path: "/pc",
        Component: require("@/pages/Pc").default,
        name: "pc端",
      },
      {
        path: "/mobile",
        Component: require("@/pages/Mobile").default,
        name: "h5端",
      },
    ],
  },
];
export default routes;
第五步
// 项目入口文件
import * as React from "react";
import store from "@/store";
import {CreateRouter} from "perkz";
import {Provider} from "react-redux";
import routers from "@/routers";

const App = () => {
  return (
    <React.Fragment>
      <Provider store={store}>
        <CreateRouter routers={routers}/>
      </Provider>
    </React.Fragment>
  );
};
2.0.1

2 years ago

2.0.0

2 years ago

1.0.16

2 years ago

1.0.15

2 years ago

1.0.14

2 years ago

1.0.13

2 years ago

1.0.12

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

0.1.12

2 years ago

0.1.11

2 years ago

0.1.10

2 years ago

0.1.9

2 years ago

0.1.8

2 years ago

0.1.7

2 years ago

0.1.6

2 years ago

0.1.5

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.0.16

2 years ago

0.0.15

2 years ago

0.0.14

2 years ago

0.0.13

2 years ago

0.0.12

2 years ago

0.0.10

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.1

2 years ago