Merge pull request #16081 from raybooysen/fix/cancelExistingDebounce

fix: If there is an existing debounce in progress, cancel that
This commit is contained in:
偏右 2019-04-15 14:50:47 +08:00 committed by GitHub
commit 321a12eb6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -98,6 +98,10 @@ class Spin extends React.Component<SpinProps, SpinState> {
}
componentWillUnmount() {
this.cancelExistingSpin();
}
cancelExistingSpin() {
const updateSpinning: any = this.updateSpinning;
if (updateSpinning && updateSpinning.cancel) {
updateSpinning.cancel();
@ -116,6 +120,7 @@ class Spin extends React.Component<SpinProps, SpinState> {
debouncifyUpdateSpinning = (props?: SpinProps) => {
const { delay } = props || this.props;
if (delay) {
this.cancelExistingSpin();
this.updateSpinning = debounce(this.originalUpdateSpinning, delay);
}
};