redux-middleware-debounce
v2.0.3
Published
FSA and RSAA compliant middleware for Redux to debounce actions.
Downloads
206
Maintainers
Readme
redux-middleware-debounce
FSA-compliant middleware for Redux to debounce actions. Based on redux-debounce
Installation
$ npm install --save redux-middleware-debounce
Usage
Simply add a debounce property to any Flux Standard Action (or any object-based action) like so:
// Store setup
import { applyMiddleware, createStore } from 'redux'
import debounce from 'redux-middleware-debounce'
import createLogger from 'redux-logger'
import promise from 'redux-promise'
import thunk from 'redux-thunk'
const logger = createLogger()
const createMiddleware = applyMiddleware(debounce)
const store = createMiddleware(createStore)(reducer)
const debounceAction = () => ({
type: 'TEST',
debounce: {
wait: 100
},
})
Debounce middleware should be placed near the top of the chain, that way the debounce property will be stripped in time for other middlewares that validate, such as redux-api-middleware
Options
All Lodash debounce() options are supported:
See lodash
const debounceAction = () => ({
type: 'TEST',
debounce: {
wait: 100,
options: {
maxWait: 1000
}
},
})
License
Copyright © 2016 Committed Software
Original examples and test code Copyright © 2015-2016 Neil Kistner. Released under the MIT license. See license for details.