From a7ce47870cac017de953842dfef0d9725559e92e Mon Sep 17 00:00:00 2001 From: Gilad Gray Date: Wed, 9 Jan 2019 14:23:35 -0800 Subject: [PATCH] refactor toast timeout update logic to be more obvious always clear timeout when starting to cancel any previous now-outdated active timer. --- packages/core/src/components/toast/toast.tsx | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/packages/core/src/components/toast/toast.tsx b/packages/core/src/components/toast/toast.tsx index d4c6231d8b..a457632c73 100644 --- a/packages/core/src/components/toast/toast.tsx +++ b/packages/core/src/components/toast/toast.tsx @@ -79,12 +79,12 @@ export class Toast extends AbstractPureComponent { } public componentDidUpdate(prevProps: IToastProps) { - if (prevProps.timeout !== this.props.timeout && this.props.timeout > 0) { - this.startTimeout(); - } else if (prevProps.timeout <= 0 && this.props.timeout > 0) { - this.startTimeout(); - } else if (prevProps.timeout > 0 && this.props.timeout <= 0) { - this.clearTimeouts(); + if (prevProps.timeout !== this.props.timeout) { + if (this.props.timeout > 0) { + this.startTimeout(); + } else { + this.clearTimeouts(); + } } } @@ -109,11 +109,12 @@ export class Toast extends AbstractPureComponent { private handleCloseClick = () => this.triggerDismiss(false); private triggerDismiss(didTimeoutExpire: boolean) { - safeInvoke(this.props.onDismiss, didTimeoutExpire); this.clearTimeouts(); + safeInvoke(this.props.onDismiss, didTimeoutExpire); } private startTimeout = () => { + this.clearTimeouts(); if (this.props.timeout > 0) { this.setTimeout(() => this.triggerDismiss(true), this.props.timeout); }