From 5467c694b34b6effcfc071bfb1e3113f2f87c486 Mon Sep 17 00:00:00 2001 From: David Sehnal <david.sehnal@gmail.com> Date: Fri, 23 Nov 2018 17:23:34 +0100 Subject: [PATCH] mol-plugin: auto-apply tweak --- src/mol-plugin/ui/state/common.tsx | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/mol-plugin/ui/state/common.tsx b/src/mol-plugin/ui/state/common.tsx index 5934dcdd0..78defcc31 100644 --- a/src/mol-plugin/ui/state/common.tsx +++ b/src/mol-plugin/ui/state/common.tsx @@ -114,13 +114,20 @@ abstract class TransformContolBase<P, S extends TransformContolBase.ControlState } private autoApplyHandle: number | undefined = void 0; + private clearAutoApply() { + if (this.autoApplyHandle !== void 0) { + clearTimeout(this.autoApplyHandle); + this.autoApplyHandle = void 0; + } + } events: StateTransformParameters.Props['events'] = { onEnter: this.onEnter, onChange: (params, isInitial, errors) => { + this.clearAutoApply(); this.setState({ params, isInitial, error: errors && errors[0] }, () => { if (!isInitial && !this.state.error && this.canAutoApply(params)) { - if (this.autoApplyHandle) clearTimeout(this.autoApplyHandle); + this.clearAutoApply(); this.autoApplyHandle = setTimeout(this.apply, 50) as any as number; } }); @@ -128,10 +135,7 @@ abstract class TransformContolBase<P, S extends TransformContolBase.ControlState } apply = async () => { - if (this.autoApplyHandle !== void 0) { - clearTimeout(this.autoApplyHandle); - this.autoApplyHandle = void 0; - } + this.clearAutoApply(); this.setState({ busy: true }); try { await this.applyAction(); -- GitLab