# redux-throttle

> Queue actions when offline and dispatch them when getting back online

Latest version **0.1.1** (published 2016-06-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install redux-throttle
pnpm add redux-throttle
yarn add redux-throttle
bun add redux-throttle
```

## 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.1.1 |
| Published | 2016-06-03 |
| First published | 2016-05-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 35 |
| Author | Mathieu Dutour |
| Maintainers | mathieudutour |

## Links

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

## Dependencies (1)

- [lodash.throttle](https://npm.io/package/lodash.throttle.md) 4.0.1

## Recent versions

- 0.1.1 (latest) — 2016-06-03
- 0.1.0 — 2016-05-28

## README

redux-throttle
=============

[![build status](https://img.shields.io/travis/mathieudutour/redux-throttle/master.svg?style=flat-square)](https://travis-ci.org/mathieudutour/redux-throttle)
[![npm version](https://img.shields.io/npm/v/redux-throttle.svg?style=flat-square)](https://www.npmjs.com/package/redux-throttle)
[![Dependency Status](https://david-dm.org/mathieudutour/redux-throttle.svg)](https://david-dm.org/mathieudutour/redux-throttle)
[![devDependency Status](https://david-dm.org/mathieudutour/redux-throttle/dev-status.svg)](https://david-dm.org/mathieudutour/redux-throttle#info=devDependencies)

Redux middleware to throttle your actions

```bash
npm install --save redux-throttle
```

## Usage

```js
import {createStore, applyMiddleware} from "redux";
import throttle from "redux-throttle";
import reducers from "./reducers";
import actionTypes from "./constants/actionTypes";

const defaultWait = 300
const defaultThrottleOption = { // https://lodash.com/docs#throttle
  leading: true,
  trailing: true
}

const middleware = throttleActions(defaultWait, defaultThrottleOption);
const store = applyMiddleware(middleware)(createStore)(reducers);
```

Then you just have to dispatch actions with the meta `throttle`:

```js
{
  type: 'ACTION_TYPE',
  meta: {
    throttle: true
  }
}

{
  type: 'ACTION_TYPE_2',
  meta: {
    throttle: 300 // wait time
  }
}

{
  type: 'ACTION_TYPE_3',
  meta: {
    throttle: {
      wait: 300,
      leading: false
    }
  }
}

```

There are 2 special actions exported by the library:

```js
import {CANCEL, FLUSH} from "redux-throttle";

dispatch({
  type: CANCEL,
  payload: {
    type: 'ACTION_TYPE'
  }
})

dispatch({
  type: FLUSH,
  payload: {
    type: ['ACTION_TYPE_2', 'ACTION_TYPE_3']
  }
})

dispatch({ // will flush everything
  type: FLUSH
})
```

Both of them can be used to respectively cancel or flush a throttled action.

## License

  MIT

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