# redux-action-thunk

> redux middleware for calling actions by name

Latest version **0.3.0** (published 2016-05-13) · ISC license · 0 weekly downloads

## Install

```sh
npm install redux-action-thunk
pnpm add redux-action-thunk
yarn add redux-action-thunk
bun add redux-action-thunk
```

## 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.3.0 |
| Published | 2016-05-13 |
| First published | 2016-05-12 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Shawn McKay |
| Maintainers | shmck |
| Keywords | redux, middleware, thunk |

## Links

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

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 0.3.0 (latest) — 2016-05-13
- 0.2.0 — 2016-05-12
- 0.1.0 — 2016-05-12

## README

# Redux Action Thunk

No more import types. Instead, register your actions on startup and call actions using middleware. Redux Action Thunk allows you to write more modular code, as you no longer have to import your store, action, or types. EVER.

### Without RAT

```js
// actions.js
import {ACTION_CALL} from './types';
export function actionCall() {
  return { type: 'ACTION_CALL' };
}

// component.js
import {actionCall} from '../../actions';

dispatch(actionCall);
```

### With RAT

Code becomes simplified, without relative paths linking to actions. You can now write redux code without loading store, actions or types in your files.

```js
// actions.js
import rat from 'redux-action-thunk';

rat.add('INCREMENT');
// creates action and type { type: 'INCREMENT '}

// component.js
dispatch('INCREMENT');
```


### Multiple Action Calls

```js
rat.add('ADD_TWO', (dispatch, getState) => {
	dispatch('INCREMENT');
	dispatch('INCREMENT');
})
```

### Does not effect regular action calls

```js
rat.add('ACTION_CALL');

dispatch({ type: 'ACTION_CALL' }); // works
dispatch('ACTION_CALL'); // works
```

### Pass in params

```js
rat.add('ADD_TOGETHER', (dispatch, getState) => (x, y) => {
	const total = x + y;
	return {
		type: 'ADD_TOGETHER',
		payload: {
			total
		}
	};
});

// dispatch an array including the param values
store.dispatch(['ADD_TOGETHER', 3, 4]);
```

## Setup

- Install the package.

`> npm install redux-action-thunk`

- load the Redux middleware

```js
// store.js
import {applyMiddleware, createStore} from 'redux';
import {ratMiddleware} from 'rat';
import reducer from '../reducers';

const store = createStore(
  reducer,
  applyMiddleware(ratMiddleware)
);

export default store;
```

- add actions

```js
// actions.js
import {rat} from 'redux-action-thunk';

rat.add('ACTION_CALL');
```

- dispatch actions

```js
store.dispatch('ACTION_CALL');
```

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