2.0.8 • Published 6 years ago

redux-whenever v2.0.8

Weekly downloads
21
License
MIT
Repository
github
Last release
6 years ago

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

Usage

Adding subscriber

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

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  ·  GitHub @caiogondim  ·  Twitter @caio_gondim

2.0.8

6 years ago

2.0.7

7 years ago

2.0.6

7 years ago

2.0.5

7 years ago

2.0.4

7 years ago

2.0.3

7 years ago

2.0.2

7 years ago

2.0.1

7 years ago

2.0.0

7 years ago