# @f/create-action

> Action creator creator for flux standard actions

Latest version **1.1.1** (published 2015-12-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install @f/create-action
pnpm add @f/create-action
yarn add @f/create-action
bun add @f/create-action
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.1 |
| Published | 2015-12-16 |
| First published | 2015-12-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Maintainers | f |

## Links

- npm: https://www.npmjs.com/package/@f/create-action
- Repository: https://github.com/micro-js/create-action
- Homepage: https://github.com/micro-js/create-action#readme
- Issues: https://github.com/micro-js/create-action/issues
- npm.io page: https://npm.io/package/@f/create-action

## Recent versions

- 1.1.1 (latest) — 2015-12-16
- 1.1.0 — 2015-12-16

## README

# create-action

[![Build status][travis-image]][travis-url]
[![Git tag][git-image]][git-url]
[![NPM version][npm-image]][npm-url]
[![Code style][standard-image]][standard-url]

Action creator creator for flux standard actions.  Very similar to the function of the same name found in [redux-actions](https://github.com/acdlite/redux-actions), but implemented as a micro-module and without the special error handling stuff.

## Installation

    $ npm install @f/create-action

## Usage

```js
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](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, which means that instead of writing this:

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

export {
  setText,
  SET_TEXT
}
```

You can just write this:

```javascript
export default createAction('SET_TEXT')
```

And then use it in a [reducer map](http://github.com/micro-js/handle-actions), like this:

```javascript
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

[travis-image]: https://img.shields.io/travis/micro-js/create-action.svg?style=flat-square
[travis-url]: https://travis-ci.org/micro-js/create-action
[git-image]: https://img.shields.io/github/tag/micro-js/create-action.svg
[git-url]: https://github.com/micro-js/create-action
[standard-image]: https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat
[standard-url]: https://github.com/feross/standard
[npm-image]: https://img.shields.io/npm/v/@f/create-action.svg?style=flat-square
[npm-url]: https://npmjs.org/package/@f/create-action

---
_Source: https://npm.io/package/@f/create-action · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
