create-redux-action-types
TypeScript icon, indicating that this package has built-in type declarations

0.1.0 • Public • Published

Create Redux Action Types

使用一个普通的javascript对象来创建 redux 的 actionTypes.

安装

npm install --save create-redux-action-types
或
yarn add create-redux-action-types

使用

文件:actions/actionTypes.ts

import createReduxActionTypes from "create-redux-action-types"

export default createReduxActionTypes(
  {
    auth: {
      login: "",
      logout: "",
    },
    user: {
      get: {
        pending: "",
        fulfilled: "",
        rejected: ""
      }
    }
  },
  "-", // 分隔符, 默认 "/"
  "app" // 命名空间, 默认 undefined
);

文件:actions/some.ts

import actionTypes from "./actionTypes"

actionTypes.auth.login          // "app-auth-login"
String(actionTypes.user.get)    // "app-user-get-"
actionTypes.user.get.pending    // "app-user-get-pending"
actionTypes.user.get.fulfilled  // "app-user-get-fulfilled"
actionTypes.user.get.rejected   // "app-user-get-rejected"

创建出来的actionTypes 就像下面这样

{
  auth: {
    login: "app-auth-login",
    logout: "app-auth-logout",
  },
  user: {
    get: {
      pending: "app-user-get-pending",
      fulfilled: "app-user-get-fulfilled",
      rejected: "app-user-get-rejected"
    }
  }
}

Package Sidebar

Install

npm i create-redux-action-types

Weekly Downloads

2

Version

0.1.0

License

MIT

Unpacked Size

60.8 kB

Total Files

12

Last publish

Collaborators

  • qinzisong