debounce-transfer
v1.2.2
Published
* `debounceWrapper`: the function to debounce * `fn`: the function of input trigger * `time`: milliseconds of setTimeout interval
Downloads
1
Readme
debounce-transfer
Wrap function into a debounce function.
Install
$ npm install debounce-transfer --save
Usage
debounce:
const debounceTransfer = require('debounce-transfer')
const debounce = debounceTransfer(fn, 300, true)
// true means excute fn after 300ms and then every 300ms
// false means excute fn immediately and then every 300ms;
function fn(a) {
console.log(a)
}
debounce('hi')
debounce('hi')
// log 'hi' once after 300ms.
excute immediately, then debounce:
const debounceTransfer = require('debounce-transfer')
const debounce = debounceTransfer(fn, 300)
function fn(a) {
console.log(a)
}
debounce('hi') // log 'hi' immediately, no delay.
debounce('hi2') // log 'hi2' after 300ms.
bind this:
const debounceTransfer = require('debounce-transfer')
const debounce = debounceTransfer(function () {
console.log(this === window)
}, 300)
window.onresize = debounce
// log 'true' when resizing the window
API
License
MIT