Created
April 26, 2019 06:16
-
-
Save demiazz/4a775daf1c273bd50128f77d71dc574d to your computer and use it in GitHub Desktop.
This file contains 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
type Action = () => void; | |
export const throttleWithRAF = (action: Action): (() => void) => { | |
let isRunning = false; | |
return (): void => { | |
if (isRunning) { | |
return; | |
} | |
isRunning = true; | |
requestAnimationFrame( | |
(): void => { | |
action(); | |
isRunning = false; | |
} | |
); | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment