redux-middleware-debounce

2.0.3 • Public • Published

redux-middleware-debounce

Build Status npm

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.

Package Sidebar

Install

npm i redux-middleware-debounce

Weekly Downloads

29

Version

2.0.3

License

MIT

Last publish

Collaborators

  • commitd_jon