# action-creator

> A simple way to write function with context dependencies without context parameter

Latest version **0.7.1** (published 2017-09-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install action-creator
pnpm add action-creator
yarn add action-creator
bun add action-creator
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.7.1 |
| Published | 2017-09-13 |
| First published | 2017-03-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | heineiuo |
| Maintainers | heineiuo |

## Links

- npm: https://www.npmjs.com/package/action-creator
- Repository: https://github.com/heineiuo/action-creator
- Homepage: https://github.com/heineiuo/action-creator#readme
- Issues: https://github.com/heineiuo/action-creator/issues
- npm.io page: https://npm.io/package/action-creator

## Recent versions

- 0.7.1 (latest) — 2017-09-13
- 0.6.3-beta.10 (next) — 2017-07-07
- 0.7.0 — 2017-09-13
- 0.6.5 — 2017-07-23
- 0.6.4 — 2017-07-23
- 0.6.3 — 2017-07-07
- 0.6.3-beta.9 — 2017-07-07
- 0.6.3-beta.8 — 2017-07-07
- 0.6.3-beta.7 — 2017-07-07
- 0.6.3-beta.6 — 2017-07-07
- 0.6.3-beta.5 — 2017-07-07
- 0.6.3-beta.4 — 2017-07-07
- 0.6.3-beta.3 — 2017-07-07
- 0.6.3-beta.2 — 2017-07-07
- 0.6.3-beta.1 — 2017-07-07
- … 12 more at https://npm.io/package/action-creator/versions

## README

# action-creator
A simple way to write function with context dependencies without context parameter

---
[中文](./README_CN.md)


## Get started

### install

```
npm install action-creator
# or
yarn add action-creator
```

### usage

```javascript
import {bindActionCreators, connect} from 'action-creator'
```



## Docs

### 1. bindActionCreators(object: actionCreators)(ctx) => object: actions

Param `actionCreators` is a object contain `action creators`, like:

```javascript
bindActionCreators({
  getIp: () => {},
  getUserName: () => {},
})

```

it will return a function, and then pass param `ctx` to this function. like:

```javascript
const ctx = {
  req: {},
  res: {}
}

bindActionCreators({
  getIp: () => {},
  getUserName: () => {},
})(ctx)
```

it will return a object contains `{getIp, getUserName}`, now you can use `getIp` directly.


### 2. connect(function: bindActionCreators(actionCreators))(beConnected) => function: wrappedActionCreator

An action is written like `(..args) => (ctx, getAction) => {...}`, so if you want to use `getAction` method,
you must `connect` it with other actions you need. like:

```javascript

const getName = (...args) => (ctx, getAction) => {
  const {getParentName} = getAction()
  return getParentName(...args) + args[1]
}
// ... after do bindActionCreators(...)(ctx), you run getName() will
// cause an Error 'getParentName is not a function'

const connectedGetName = connect(
  bindActionCreators({
    getParentName
  })
)(getName)
// this will be ok

```

## License

MIT

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