Browse Source

StructureFocusManager.behaviors.current
replaces events.changed

David Sehnal 5 years ago
parent
commit
2f4f5e43f3

+ 7 - 3
src/mol-plugin-state/manager/structure/focus.ts

@@ -2,6 +2,7 @@
  * Copyright (c) 2020 mol* contributors, licensed under MIT, See LICENSE file for more info.
  *
  * @author Alexander Rose <alexander.rose@weirdbyte.de>
+ * @author David Sehnal <david.sehnal@gmail.com>
  */
 
 import { StatefulPluginComponent } from '../../component';
@@ -28,10 +29,13 @@ const HISTORY_CAPACITY = 4;
 export class StructureFocusManager extends StatefulPluginComponent<StructureFocusManagerState> {
 
     readonly events = {
-        changed: this.ev<undefined>(),
         historyUpdated: this.ev<undefined>()
     }
 
+    readonly behaviors = {
+        current: this.ev.behavior<FocusEntry | undefined>(void 0)
+    };
+
     get current() { return this.state.current; }
     get history() { return this.state.history; }
 
@@ -67,7 +71,7 @@ export class StructureFocusManager extends StatefulPluginComponent<StructureFocu
         this.tryAddHistory(entry)
         if (!this.state.current || !StructureElement.Loci.areEqual(this.state.current.loci, entry.loci)) {
             this.state.current = entry
-            this.events.changed.next()
+            this.behaviors.current.next(entry)
         }
     }
 
@@ -96,7 +100,7 @@ export class StructureFocusManager extends StatefulPluginComponent<StructureFocu
     clear() {
         if (this.state.current) {
             this.state.current = undefined
-            this.events.changed.next()
+            this.behaviors.current.next(void 0)
         }
     }
 

+ 1 - 1
src/mol-plugin-ui/structure/focus.tsx

@@ -70,7 +70,7 @@ export class StructureFocusControls extends PluginUIComponent<{}, StructureFocus
     state = { isBusy: false, showAction: false }
 
     componentDidMount() {
-        this.subscribe(this.plugin.managers.structure.focus.events.changed, c => {
+        this.subscribe(this.plugin.managers.structure.focus.behaviors.current, c => {
             this.forceUpdate();
         });
 

+ 1 - 2
src/mol-plugin/behavior/dynamic/selection/structure-focus-representation.ts

@@ -143,8 +143,7 @@ export class StructureFocusRepresentationBehavior extends PluginBehavior.WithSub
     }
 
     register(ref: string): void {
-        this.subscribeObservable(this.plugin.managers.structure.focus.events.changed, () => {
-            const entry = this.plugin.managers.structure.focus.current
+        this.subscribeObservable(this.plugin.managers.structure.focus.behaviors.current, (entry) => {
             if (entry) this.focus(entry.loci)
             else this.clear(StateTransform.RootRef)
         });

+ 8 - 16
src/mol-plugin/behavior/dynamic/volume-streaming/behavior.ts

@@ -234,23 +234,15 @@ export namespace VolumeStreaming {
                 }
             });
 
-            this.subscribeObservable(this.plugin.managers.structure.focus.events.changed, () => {
-                this.updateFromFocus()
+            this.subscribeObservable(this.plugin.managers.structure.focus.behaviors.current, (entry) => {
+                const loci = entry ? entry.loci : EmptyLoci
+    
+                if (this.params.entry.params.view.name !== 'selection-box') {
+                    this.lastLoci = loci;
+                } else {
+                    this.updateInteraction(loci)
+                }
             });
-
-            // ensure current focus is shown if needed upon registering
-            this.updateFromFocus()
-        }
-
-        private updateFromFocus() {
-            const entry = this.plugin.managers.structure.focus.current
-            const loci = entry ? entry.loci : EmptyLoci
-
-            if (this.params.entry.params.view.name !== 'selection-box') {
-                this.lastLoci = loci;
-            } else {
-                this.updateInteraction(loci)
-            }
         }
 
         private getBoxFromLoci(loci: StructureElement.Loci | EmptyLoci): Box3D {