@f/create-action

中文文档
1.1.1发布于 2015/12/16MITCommonJS零依赖近 30 天下载 2130

Action creator creator for flux standard actions

原始使用文档
文档目录7 节
  1. Installation
  2. Usage
  3. API
  4. createAction(type, payloadCreator, metaCreator)
  5. toString sugar
  6. type property
  7. License

create-action

Build status Git tag NPM version Code style

Action creator creator for flux standard actions. Very similar to the function of the same name found in redux-actions, but implemented as a micro-module and without the special error handling stuff.

Installation

$ npm install @f/create-action

Usage

var createAction = require('@f/create-action')
var incrementBy = createAction(INCREMENT_BY)

// ...

dispatch(incrementBy(2))

API

createAction(type, payloadCreator, metaCreator)

  • type - String or other identifier that represents the type of the action to create
  • payloadCreator - Function that produces payload from the arguments to the action creator (optional - defaults to https://github.com/micro-js/identity)
  • metaCreator - Function that produces meta from the arguments to the action creator (optional)

Returns: An action creator that creates an action according to the arguments specified.

toString sugar

Action creators returned by createAction override Function.prototype.toString, and instead return the type string. This allows the function to double as the action type, for useThis means that instead of writing this:

const SET_TEXT = 'SET_TEXT'
const setText = createAction('SET_TEXT')

export {
  setText,
  SET_TEXT
}

You can just write this:

export default createAction('SET_TEXT')

And then use it in a reducer map, like this:

combineReducers({
  text: handleActions({
    [setText]: (state, text) => text
  })
})

type property

If abusing toString as above makes you squeamish, then the type is also set on the type property of the action creator, so that you can access it that way as well, if you prefer.

License

MIT

版本与发布记录

@f/create-action 共发布 2 个版本,首次发布于 2015/12/16;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.1.1latest2015/12/1610 年前
1.1.02015/12/1610 年前

关于 @f/create-action 的常见问题

@f/create-action 是什么?

Action creator creator for flux standard actions

如何安装 @f/create-action?

在项目目录运行 npm install @f/create-action,或使用 pnpm add / yarn add / bun add。

@f/create-action 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/f__create-action 是否存在。

@f/create-action 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@f/create-action 可以商用吗?

@f/create-action 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@f/create-action 的下载量有多少?

根据 npm 官方下载统计,@f/create-action 在 2026/10/14 – 2026/11/12 这 30 天内被下载 2,130 次,日均约 71 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@f/create-action 还在维护吗?

最新版本 1.1.1 发布于 2015/12/16(10 年前);至今共发布 2 个版本,其中过去 12 个月发布了 0 个;首次发布于 2015/12/16。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。