Browse Source

isBusy behavior bugfix
- was causing the animation button not to display if the state was loaded too fast

David Sehnal 5 years ago
parent
commit
0f3ef61f7d
1 changed files with 11 additions and 8 deletions
  1. 11 8
      src/mol-plugin/context.ts

+ 11 - 8
src/mol-plugin/context.ts

@@ -85,6 +85,9 @@ export class PluginContext {
         state: {
             isAnimating: this.ev.behavior<boolean>(false),
             isUpdating: this.ev.behavior<boolean>(false),
+            // TODO: should there be separate "updated" event?
+            //   Often, this is used to indicate that the state has updated
+            //   and it might not be the best way to react to state updates.
             isBusy: this.ev.behavior<boolean>(false)
         },
         interaction: {
@@ -257,7 +260,11 @@ export class PluginContext {
 
         let timeout: any = void 0;
         const setBusy = () => {
-            isBusy.next(true);
+            if (!isBusy.value) isBusy.next(true);
+        };
+        const reset = () => {
+            if (timeout !== void 0) clearTimeout(timeout);
+            timeout = void 0;
         };
 
         merge(this.behaviors.state.isUpdating, this.behaviors.state.isAnimating).subscribe(v => {
@@ -265,15 +272,11 @@ export class PluginContext {
             const isAnimating = this.behaviors.state.isAnimating.value;
 
             if ((isUpdating || isAnimating) && !isBusy.value) {
-                if (timeout !== void 0) clearTimeout(timeout);
+                reset();
                 timeout = setTimeout(setBusy, timeoutMs);
-                // isBusy.next(true);
             } else {
-                if (timeout !== void 0) clearTimeout(timeout);
-                timeout = void 0;
-                if (isBusy.value) {
-                    isBusy.next(false);
-                }
+                reset();
+                isBusy.next(false);
             }
         });