Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid unnecessary clearTimeouts in debounce() #304

Merged
merged 1 commit into from
Aug 26, 2014

Conversation

brettstimmerman
Copy link
Contributor

debounce() used to return a function that when first invoked always called
clearTimeout before setTimeout, even if there was no timeout to clear.

This change adds a guard to prevent such unnecessary clearTimeout calls.
The performance implications are likely minimal, but the boolean check should
perform better in general than what amounts to a noop function call when
timeout is null. As well, devtools timelines will no longer display a
not-useful "Remove Timer" scripting blip for unnecessary clearTimeouts.

debounce() used to return a function that when first invoked always called
`clearTimeout` before `setTimeout`, even if there was no timeout to clear.

This change adds a guard to prevent such unnecessary `clearTimeout` calls.
The performance implications are likely minimal, but the boolean check should
perform better in general than what amounts to a noop function call when
`timeout` is `null`. As well, devtools timelines will no longer display a
not-useful "Remove Timer" scripting blip for unnecessary `clearTimeout`s.
angus-c added a commit that referenced this pull request Aug 26, 2014
Avoid unnecessary clearTimeouts in debounce()
@angus-c angus-c merged commit 8cbb941 into master Aug 26, 2014
@necolas necolas deleted the avoid-clearTimeout-in-debounce branch October 29, 2014 17:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants