# redux-whenever

> Fires a callback whenever a store subtree turns to a desired value

Latest version **2.0.8** (published 2017-11-23) · MIT license · 0 weekly downloads

## Install

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

## 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 | 2.0.8 |
| Published | 2017-11-23 |
| First published | 2017-03-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 21 |
| Maintainers | caiogondim, markx |

## Links

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

## Dependencies (1)

- [safe-chain](https://npm.io/package/safe-chain.md) ^3.0.1

## Recent versions

- 2.0.8 (latest) — 2017-11-23
- 2.0.7 — 2017-11-02
- 2.0.6 — 2017-10-20
- 2.0.5 — 2017-10-19
- 2.0.4 — 2017-03-27
- 2.0.3 — 2017-03-27
- 2.0.2 — 2017-03-22
- 2.0.1 — 2017-03-22
- 2.0.0 — 2017-03-21

## README

<img src="https://cdn.rawgit.com/caiogondim/redux-whenever.js/master/img/banner.svg">

<h1 align="center">redux-whenever.js</h1>

<div align="center">
<img src="http://travis-ci.org/caiogondim/redux-whenever.js.svg?branch=master" alt="Travis CI"> <img src="https://codecov.io/gh/caiogondim/redux-whenever.js/branch/master/graph/badge.svg" alt="Codecov"> <img src="http://img.badgesize.io/caiogondim/redux-whenever.js/master/dist/redux-whenever.min.js?compression=gzip"> <a href="https://www.npmjs.com/package/redux-whenever"><img src="https://img.shields.io/npm/v/redux-whenever.svg" /></a>
</div>

<br>

Subscribe to a state subtree (or leaf) and run callbacks `whenever` it evaluates to a given value.

## Usage

### Adding subscriber

```js
const whenever = require('redux-whenever')
const redux = require('redux')

// Pass `whenever` as an enhancer
const store = redux.createStore(reducer, whenever)

// Pass the state selector you are interested in as a string.
// `callback` will execute only when `player.isReady` becames `true`
store.whenever('player.isReady', true, (curState, prevState) => {
  // Your magic here
})
```

### Removing subscriber
```js
const unsubscribe = store.whenever('player.isReady', true, callback)
unsubscribe() // Removes previously added listener
```

## API

### `const unsubscribe = store.whenever(selector, assertion, callback)`
Returns a function that, if called, removes the added subscriber.

#### `selector`
- type: `String|Function`

Should return a piece of the state tree

#### `assertion`
- type: `String|Number|Object|Function`

If a function, it will be executed. If not, it's equality will be compared against current state.

#### `callback`
- type: `Function`

## Installation

```
npm install --save redux-whenever
```

## Credits
- Icon by Scott Lewis from the Noun Project

---

[caiogondim.com](https://caiogondim.com) &nbsp;&middot;&nbsp;
GitHub [@caiogondim](https://github.com/caiogondim) &nbsp;&middot;&nbsp;
Twitter [@caio_gondim](https://twitter.com/caio_gondim)

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