-
Notifications
You must be signed in to change notification settings - Fork 54
fix: use and mock lodash debounce in Carousel and Dropdown #2203
Conversation
componentWillUnmount() { | ||
clearTimeout(this.a11yStatusTimeout) | ||
clearTimeout(this.charKeysPressedTimeout) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add an cancel()
call for _.debounce
:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you mean this.clearStartingString.cancel()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this.focusItemAtIndex.cancel()
as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Solved. Thanks!
Perf comparison
Generated by 🚫 dangerJS |
@@ -213,8 +212,7 @@ class Carousel extends AutoControlledComponent<WithAsProp<CarouselProps>, Carous | |||
itemRefs = [] as React.RefObject<HTMLElement>[] | |||
paddleNextRef = React.createRef<HTMLElement>() | |||
paddlePreviousRef = React.createRef<HTMLElement>() | |||
|
|||
focusItemAtIndex = debounce((index: number) => { | |||
focusItemAtIndex = _.debounce((index: number) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor nullref edge case if you don't cancel this.
fd6f063
to
c803d83
Compare
Removed in-house implementation of
debounce
and replaced its uses with_.debounce
inDropdown
andCarousel
.Properly mocked the function in
Dropdown-test
as it wasn't working with jest timers. Details in jestjs/jest#3465 and other similar Github issues.