Skip to content

Creates a debounced version of the given function which waits to execute until its last call within a given time period.

License

Notifications You must be signed in to change notification settings

goodtimeaj/debounce-function

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

Creates a debounced version of the given function which waits to execute until its last call within a given time period.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published