Skip to content

Instantly share code, notes, and snippets.

@dennisslimmers
Created November 24, 2017 14:16
Show Gist options
  • Save dennisslimmers/f1d48779a1b5b54481e795c34b8322ac to your computer and use it in GitHub Desktop.
Save dennisslimmers/f1d48779a1b5b54481e795c34b8322ac to your computer and use it in GitHub Desktop.
Typescript debounce function
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