debounce-on

0.0.0 • Public • Published

debounce-on

debounce a function based on its arguments

Install

$ npm install debounce-on

Use

For instance, you might want to rate-limit a client on a per-endpoint basis:

var debounceOn = require('debounce-on');
 
var debounceHttp = debounceOn(sendHttpRequest);
debounceHttp('https://google.com');
debounceHttp('https://google.com');
debounceHttp('https://yahoo.com');
 
// ... wait 100ms
 
// one request is sent to:
// - google.com
// - yahoo.com

You can pass a hash function that determines what calls the debouncer should coalesce:

var debounceOn = require('debounce-on');
 
var debounceHttp = debounceOn(sendHttpRequest, function (url) {
  return (url.match(/^https?:\/\/([^\/])\/?/) || {})[1];
});
debounceHttp('https://google.com/a');
debounceHttp('https://google.com/b');
debounceHttp('https://yahoo.com');
 
// ... wait 100ms
 
// one request is sent to:
// - google.com/a
// - yahoo.com

API

ver debouncedFn = debounceOn(fn, [timeout], [hash fn]);

fn

The function to debounce.

timeout

The timeout in ms.

hashFn

Function that determines what calls the debouncer should coalesce.

License

MIT

Readme

Keywords

Package Sidebar

Install

npm i debounce-on

Weekly Downloads

7

Version

0.0.0

License

MIT

Last publish

Collaborators

  • btford