Created
January 15, 2019 18:11
-
-
Save JasonStoltz/9cddcc63f5eacf5258ed86b2406e8cbe to your computer and use it in GitHub Desktop.
Debounce 1 tick
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
| const debounce = (() => { | |
| let wasCalled = false; | |
| let fn = null; | |
| return newFn => { | |
| fn = newFn; | |
| if (!wasCalled) { | |
| wasCalled = true; | |
| setTimeout(() => { | |
| wasCalled = false; | |
| return fn(); | |
| }); | |
| } | |
| }; | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment