Skip to content

Latest commit

 

History

History
69 lines (47 loc) · 1.32 KB

File metadata and controls

69 lines (47 loc) · 1.32 KB

Debounce Function

Creates a debounced version of the given function which waits to execute until its last call within a given time period. Supports an option to prevent subsequent execution of the function after the first execution.

Usage

Include

Script include creates global DebounceFunction:

<script src="debounce-function.min.js"></script>

AMD:

<script src="debounce-function.min.js"></script>
<script>
  define(['debounce-function'], function(DebounceFunction) {
    // do something
  })
</script>

CommonJS:

$ npm install debounce-function
var DebounceFunction = require('debounce-function')

API

DebounceFunction.get() returns a new function that is the given function in a debounced wrapper.

var foo = function() {
  console.log('foo')
}

// Get a debounced variant of `foo`
var debouncedFoo = DebounceFunction.get(foo, 100)

// Get a debounced variant of `foo`, set to execute only once
var debouncedFooOnlyOnce = DebounceFunction.get(foo, 100, true)

Development

$ cd debounce-function
$ npm install
$ grunt install
$ grunt build
$ grunt test

# Build for release
$ grunt dist

License

Copyright (c) 2016 Greg Stallings. See LICENSE for details.