If there is an existing debounce in progress, cancel that

This commit is contained in:
Ray Booysen 2019-04-15 14:30:04 +08:00
parent d9d189e053
commit fe1617bc5c

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);
}
};