Skip to content

Instantly share code, notes, and snippets.

@dswitzer
dswitzer / fireThenDebounce.js
Created February 2, 2018 19:20
fireThenDebounce() - A variation of a debounce handler which fires off code at the start and end of the execution call stack
/*
* fireThenDebounce(delay, immediate, tail)
*
* delay - number of milliseconds in which to debounce the `trail` callback
* immediate - function to run when the debounce handler starts
* tail - the debounced function to run after the inactive delay is reached
*
* This is a special version of a debounce handler, which allows you to trigger
* off code to run at the start and end of a debounced event. A normal debounce
* event only fires when a debounced event ends.