Browse Source

mol-plugin: auto-apply tweak

David Sehnal 6 years ago
parent
commit
5467c694b3
1 changed files with 9 additions and 5 deletions
  1. 9 5
      src/mol-plugin/ui/state/common.tsx

+ 9 - 5
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();