# redux-batched-subscribe

> redux store enhancer which allows batching subscribe notifications.

Latest version **0.1.6** (published 2016-06-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install redux-batched-subscribe
pnpm add redux-batched-subscribe
yarn add redux-batched-subscribe
bun add redux-batched-subscribe
```

## Health

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

Positive: has types package; no vulnerabilities; high quality score.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.6 |
| Published | 2016-06-04 |
| First published | 2015-08-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/redux-batched-subscribe) |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 501 |
| Author | Terry Appleby |
| Maintainers | tappleby |
| Keywords | redux, batched, react, reactjs, performance, store |

## Links

- npm: https://www.npmjs.com/package/redux-batched-subscribe
- Repository: https://github.com/tappleby/redux-batched-subscribe
- Issues: https://github.com/tappleby/redux-batched-subscribe/issues
- npm.io page: https://npm.io/package/redux-batched-subscribe

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 0.1.6 (latest) — 2016-06-04
- 0.1.5 — 2016-05-15
- 0.1.4 — 2015-08-15
- 0.1.3 — 2015-08-15
- 0.1.2 — 2015-08-03
- 0.1.1 — 2015-08-03
- 0.1.0 — 2015-08-03

## README

redux-batched-subscribe
=====================

[![build status](https://img.shields.io/travis/tappleby/redux-batched-subscribe/master.svg?style=flat-square)](https://travis-ci.org/tappleby/redux-batched-subscribe)
[![npm version](https://img.shields.io/npm/v/redux-batched-subscribe.svg?style=flat-square)](https://www.npmjs.com/package/redux-batched-subscribe)

Store enhancer for [redux](https://github.com/rackt/redux) which allows batching of subscribe notifications that occur as a result of dispatches.

```js
npm install --save redux-batched-subscribe
```

## Usage

The `batchedSubscribe` store enhancer accepts a function which is called after every dispatch with a `notify` callback as a single argument. Calling the `notify` callback will trigger all the subscription handlers, this gives you the ability to use various techniques to delay subscription notifications such as: debouncing, React batched updates or requestAnimationFrame.

Since `batchedSubscribe` overloads the dispatch and subscribe handlers on the original redux store it is important that it gets applied before any other store enhancers or middleware that depend on these functions; The [compose](https://github.com/rackt/redux/blob/master/docs/api/compose.md) utility in redux can be used to handle this:

```js
import { createStore, applyMiddleware, compose } from 'redux';
import { batchedSubscribe } from 'redux-batched-subscribe';

const enhancer = compose(
  applyMiddleware(...middleware),
  batchedSubscribe((notify) => {
    notify();
  })
)

// Note: passing enhancer as the last argument to createStore requires redux@>=3.1.0
const store = createStore(reducer, initialState, enhancer);
```

*Note: since `compose` applies functions from right to left, `batchedSubscribe` should appear at the end of the chain.*

The store enhancer also exposes a `subscribeImmediate` method which allows for unbatched subscribe notifications.

## Examples

### Debounced subscribe handlers:

```js
import { createStore } from 'redux';
import { batchedSubscribe } from 'redux-batched-subscribe';
import debounce from 'lodash.debounce';

const batchDebounce = debounce(notify => notify());
const finalCreateStore = batchedSubscribe(batchDebounce)(createStore);
const store = finalCreateStore(reducer, intialState);
```

### React batched updates

```js
import { createStore } from 'redux';
import { batchedSubscribe } from 'redux-batched-subscribe';

// React <= 0.13
import { addons } from 'react/addons';
const batchedUpdates = addons.batchedUpdates;

// React 0.14
import { unstable_batchedUpdates as batchedUpdates } from 'react-dom';

// Note: passing batchedSubscribe as the last argument to createStore requires redux@>=3.1.0
const store = createStore(reducer, intialState, batchedSubscribe(batchedUpdates));
```

## Thanks

Thanks to [Andrew Clark](https://github.com/acdlite) for the clean library structure.

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