This repository has been archived by the owner on Mar 4, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: use and mock lodash debounce in Carousel and Dropdown (#2203)
* use lodash debounce and mock it * changelog * cleanup * mock in Carousel tests as well * cancel the debounced function in carousel * mock lodash in file
- Loading branch information
1 parent
540c9a2
commit 7491e57
Showing
6 changed files
with
25 additions
and
26 deletions.
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
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