This repository has been archived by the owner on Mar 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 54
fix: use and mock lodash debounce in Carousel and Dropdown #2203
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
963c639
use lodash debounce and mock it
silviuaavram 8e96db2
changelog
silviuaavram ec50e47
cleanup
silviuaavram 22faa0f
mock in Carousel tests as well
silviuaavram b5c06f7
cancel the debounced function in carousel
silviuaavram c803d83
mock lodash in file
silviuaavram File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -344,6 +344,11 @@ class Dropdown extends AutoControlledComponent<WithAsProp<DropdownProps>, Dropdo | |
static SearchInput = DropdownSearchInput | ||
static SelectedItem = DropdownSelectedItem | ||
|
||
componentWillUnmount() { | ||
this.clearStartingString.cancel() | ||
this.clearA11ySelectionMessage.cancel() | ||
} | ||
|
||
getInitialAutoControlledState({ multiple, search }: DropdownProps): DropdownState { | ||
return { | ||
a11ySelectionStatus: '', | ||
|
@@ -361,15 +366,8 @@ class Dropdown extends AutoControlledComponent<WithAsProp<DropdownProps>, Dropdo | |
} | ||
} | ||
|
||
a11yStatusTimeout: any | ||
charKeysPressedTimeout: any | ||
defaultTriggerButtonId = _.uniqueId('dropdown-trigger-button-') | ||
|
||
componentWillUnmount() { | ||
clearTimeout(this.a11yStatusTimeout) | ||
clearTimeout(this.charKeysPressedTimeout) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you mean There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Solved. Thanks! |
||
|
||
/** | ||
* Used to compute the filtered items (by value and search query) and, if needed, | ||
* their string equivalents, in order to be used throughout the component. | ||
|
@@ -1348,20 +1346,22 @@ class Dropdown extends AutoControlledComponent<WithAsProp<DropdownProps>, Dropdo | |
* so it is not read anymore via virtual cursor. | ||
*/ | ||
setA11ySelectionMessage = (a11ySelectionStatus: string): void => { | ||
clearTimeout(this.a11yStatusTimeout) | ||
this.setState({ a11ySelectionStatus }) | ||
this.a11yStatusTimeout = setTimeout(() => { | ||
this.setState({ a11ySelectionStatus: '' }) | ||
}, Dropdown.a11yStatusCleanupTime) | ||
this.clearA11ySelectionMessage() | ||
} | ||
|
||
setStartingString = (startingString: string): void => { | ||
clearTimeout(this.charKeysPressedTimeout) | ||
this.setState({ startingString }) | ||
this.charKeysPressedTimeout = setTimeout(() => { | ||
this.setState({ startingString: '' }) | ||
}, Dropdown.charKeyPressedCleanupTime) | ||
this.clearStartingString() | ||
} | ||
|
||
clearA11ySelectionMessage = _.debounce(() => { | ||
this.setState({ a11ySelectionStatus: '' }) | ||
}, Dropdown.a11yStatusCleanupTime) | ||
|
||
clearStartingString = _.debounce(() => { | ||
this.setState({ startingString: '' }) | ||
}, Dropdown.charKeyPressedCleanupTime) | ||
} | ||
|
||
Dropdown.slotClassNames = { | ||
|
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
10 changes: 3 additions & 7 deletions
10
packages/react/src/utils/debounce.ts → packages/react/test/__mocks__/lodash.ts
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,19 @@ | ||
const debounce = (fn: Function, time: number): Function => { | ||
// @ts-ignore | ||
export * from 'lodash' | ||
export const debounce = (fn: Function, time: number): Function => { | ||
let timeoutId | ||
|
||
function cancel() { | ||
if (timeoutId) { | ||
clearTimeout(timeoutId) | ||
} | ||
} | ||
|
||
function wrapper(...args) { | ||
cancel() | ||
timeoutId = setTimeout(() => { | ||
timeoutId = null | ||
fn(...args) | ||
}, time) | ||
} | ||
|
||
wrapper.cancel = cancel | ||
|
||
return wrapper | ||
} | ||
|
||
export default debounce |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.