Created
November 24, 2017 14:16
-
-
Save dennisslimmers/f1d48779a1b5b54481e795c34b8322ac to your computer and use it in GitHub Desktop.
Typescript debounce function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private _debounce(func, wait, immediate) { | |
let timeout; | |
return () => { | |
const context = this; | |
const later = () => { | |
timeout = null; | |
if (!immediate) func.apply(context); | |
}; | |
const callNow = immediate && !timeout; | |
clearTimeout(timeout); | |
timeout = setTimeout(later, wait); | |
if (callNow) func.apply(context); | |
}; | |
}; | |
const init = this._debounce(() => { | |
var cropper = new Cropper.init(); | |
}, 10, false); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment