Skip to content

Instantly share code, notes, and snippets.

@tit
Last active February 1, 2021 07:29
Show Gist options
  • Save tit/1e7051f6b9b80b96fc4fdee5e41f250a to your computer and use it in GitHub Desktop.
Save tit/1e7051f6b9b80b96fc4fdee5e41f250a to your computer and use it in GitHub Desktop.
Create AntiFool Button
function setSensitivity(element: HTMLElement, callback: () => void, timeout: number = 500): void {
let sensitivityTimer: number;
element
.addEventListener('mousedown', () => {
sensitivityTimer = setTimeout(callback, timeout);
});
element
.addEventListener('mouseup', () => {
clearTimeout(sensitivityTimer);
});
}
@RinatRezyapov-InCountry
Copy link

You could pass callback to setTimeout without wrapping it into additional arrow function (since callback is already a function)
sensitivityTimer = setTimeout(callback, timeout)
Overall LGTM

@tit
Copy link
Author

tit commented Feb 1, 2021

You could pass callback to setTimeout without wrapping it into additional arrow function (since callback is already a function)
sensitivityTimer = setTimeout(callback, timeout)

Thanks! You're right, I overdid it a bit. Made changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment