dettle
A tiny fully-featured debounce and throttle implementation.
Last updated 2 years ago by fabiospampinato .
Repository · Bugs · Original npm · Tarball · package.json
$ gnpm install dettle 
SYNC missed versions from official npm registry.

Dettle

A tiny fully-featured debounce and throttle implementation.

Install

npm install --save dettle

Usage

import {debounce, throttle} from 'dettle';

const fn = () => console.log ( 'Fired!' );

// Debouncing

const debounced = debounce ( fn, 1000, {
  leading: false,
  maxWait: 3000
});

debounced (); // Schedule function for execution
debounced (); // Re-schedule function for execution

debounced.flush (); // Execute the function immediately, if there's a scheduled execution
debounced.cancel (); // Cancel the scheduled execution

// Throttling
// The API for throttling is basically the same, except that:
// - `maxWait` is set implicitly for you to be equal to the wait time
// - `leading` is `true` by default rather than `false`

const throttled = throttle ( fn, 1000 );

throttled (); // Call the function immediately
throttled (); // Schedule function for execution

throttled.flush (); // Execute the function immediately, if there's a scheduled execution
throttled.cancel (); // Cancel the scheduled execution

License

MIT © Fabio Spampinato

Current Tags

  • 1.0.1                                ...           latest (2 years ago)

2 Versions

  • 1.0.1                                ...           2 years ago
  • 1.0.0                                ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 2
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (3)
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |