Browse Source

mol-plugin: moved state related events to PluginState

David Sehnal 5 years ago
parent
commit
cfe4c6c559

+ 1 - 1
src/extensions/rcsb/assembly-symmetry/ui.tsx

@@ -40,7 +40,7 @@ export class AssemblySymmetryControls extends CollapsableControls<{}, AssemblySy
                 description: StructureHierarchyManager.getSelectedStructuresDescription(this.plugin)
             });
         });
-        this.subscribe(this.plugin.events.state.cell.stateUpdated, e => {
+        this.subscribe(this.plugin.state.events.cell.stateUpdated, e => {
             if (e.cell.transform.transformer === AssemblySymmetry3D) this.forceUpdate();
         });
         this.subscribe(this.plugin.behaviors.state.isBusy, v => this.setState({ isBusy: v }));

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

@@ -135,7 +135,7 @@ export class StructureFocusManager extends StatefulPluginComponent<StructureFocu
         this.set({ label, loci, category });
     }
 
-    // this.subscribeObservable(this.plugin.events.state.object.updated, o => {
+    // this.subscribeObservable(this.plugin.state.events.object.updated, o => {
     //     if (!PluginStateObject.Molecule.Structure.is(o.oldObj) || !StructureElement.Loci.is(lastLoci)) return;
     //     if (lastLoci.structure === o.oldObj.data) {
     //         lastLoci = EmptyLoci;

+ 2 - 2
src/mol-plugin-ui/left-panel.tsx

@@ -146,11 +146,11 @@ class FullSettings extends PluginUIComponent {
 
 class RemoveAllButton extends PluginUIComponent<{ }> {
     componentDidMount() {
-        this.subscribe(this.plugin.events.state.cell.created, e => {
+        this.subscribe(this.plugin.state.events.cell.created, e => {
             if (e.cell.transform.parent === StateTransform.RootRef) this.forceUpdate();
         });
 
-        this.subscribe(this.plugin.events.state.cell.removed, e => {
+        this.subscribe(this.plugin.state.events.cell.removed, e => {
             if (e.parent === StateTransform.RootRef) this.forceUpdate();
         });
     }

+ 3 - 3
src/mol-plugin-ui/sequence.tsx

@@ -199,19 +199,19 @@ export class SequenceView extends PluginUIComponent<{ }, SequenceViewState> {
     componentDidMount() {
         if (this.plugin.state.data.select(StateSelection.Generators.rootsOfType(PSO.Molecule.Structure)).length > 0) this.setState(this.getInitialState());
 
-        this.subscribe(this.plugin.events.state.object.updated, ({ ref, obj }) => {
+        this.subscribe(this.plugin.state.events.object.updated, ({ ref, obj }) => {
             if (ref === this.state.structureRef && obj && obj.type === PSO.Molecule.Structure.type && obj.data !== this.state.structure) {
                 this.setState(this.getInitialState());
             }
         });
 
-        this.subscribe(this.plugin.events.state.object.created, ({ obj }) => {
+        this.subscribe(this.plugin.state.events.object.created, ({ obj }) => {
             if (obj && obj.type === PSO.Molecule.Structure.type) {
                 this.setState(this.getInitialState());
             }
         });
 
-        this.subscribe(this.plugin.events.state.object.removed, ({ obj }) => {
+        this.subscribe(this.plugin.state.events.object.removed, ({ obj }) => {
             if (obj && obj.type === PSO.Molecule.Structure.type && obj.data === this.state.structure) {
                 this.setState(this.getInitialState());
             }

+ 1 - 1
src/mol-plugin-ui/state/actions.tsx

@@ -22,7 +22,7 @@ export class StateObjectActions extends PluginUIComponent<{ state: State, nodeRe
         //     this.setState(createStateObjectActionSelectState(this.props));
         // });
 
-        this.subscribe(this.plugin.events.state.object.updated, ({ ref, state }) => {
+        this.subscribe(this.plugin.state.events.object.updated, ({ ref, state }) => {
             const current = this.current;
             if (current.ref !== ref || current.state !== state) return;
             this.forceUpdate();

+ 6 - 6
src/mol-plugin-ui/state/tree.tsx

@@ -22,11 +22,11 @@ export class StateTree extends PluginUIComponent<{ state: State }, { showActions
     state = { showActions: true };
 
     componentDidMount() {
-        this.subscribe(this.plugin.events.state.cell.created, e => {
+        this.subscribe(this.plugin.state.events.cell.created, e => {
             if (e.cell.transform.parent === StateTransform.RootRef) this.forceUpdate();
         });
 
-        this.subscribe(this.plugin.events.state.cell.removed, e => {
+        this.subscribe(this.plugin.state.events.cell.removed, e => {
             if (e.parent === StateTransform.RootRef) this.forceUpdate();
         });
     }
@@ -61,7 +61,7 @@ class StateTreeNode extends PluginUIComponent<{ cell: StateObjectCell, depth: nu
     }
 
     componentDidMount() {
-        this.subscribe(this.plugin.events.state.cell.stateUpdated, e => {
+        this.subscribe(this.plugin.state.events.cell.stateUpdated, e => {
             if (this.props.cell === e.cell && this.is(e) && e.state.cells.has(this.ref)) {
                 if (this.state.isCollapsed !== !!e.cell.state.isCollapsed
                     || this.state.isNull !== StateTreeNode.isNull(e.cell)
@@ -71,13 +71,13 @@ class StateTreeNode extends PluginUIComponent<{ cell: StateObjectCell, depth: nu
             }
         });
 
-        this.subscribe(this.plugin.events.state.cell.created, e => {
+        this.subscribe(this.plugin.state.events.cell.created, e => {
             if (this.props.cell.parent === e.state && this.ref === e.cell.transform.parent) {
                 this.forceUpdate();
             }
         });
 
-        this.subscribe(this.plugin.events.state.cell.removed, e => {
+        this.subscribe(this.plugin.state.events.cell.removed, e => {
             if (this.props.cell.parent === e.state && this.ref === e.parent) {
                 this.forceUpdate();
             }
@@ -157,7 +157,7 @@ class StateTreeNodeLabel extends PluginUIComponent<{ cell: StateObjectCell, dept
     }
 
     componentDidMount() {
-        this.subscribe(this.plugin.events.state.cell.stateUpdated.pipe(filter(e => this.is(e)), debounceTime(33)), e => {
+        this.subscribe(this.plugin.state.events.cell.stateUpdated.pipe(filter(e => this.is(e)), debounceTime(33)), e => {
             this.forceUpdate();
         });
 

+ 2 - 2
src/mol-plugin-ui/state/update-transform.tsx

@@ -72,7 +72,7 @@ class UpdateTransformControl extends TransformControlBase<UpdateTransformControl
 
         if (this.props.toggleCollapsed) this.subscribe(this.props.toggleCollapsed, () => this.setState({ isCollapsed: !this.state.isCollapsed }));
 
-        this.subscribe(this.plugin.events.state.object.updated, ({ ref, state }) => {
+        this.subscribe(this.plugin.state.events.object.updated, ({ ref, state }) => {
             if (this.props.transform.ref !== ref || this.props.state !== state) return;
             if (this.state.params !== this.props.transform.params) {
                 this._getInfo = memoizeLatest((t: StateTransform) => StateTransformParameters.infoFromTransform(this.plugin, this.props.state, t));
@@ -100,7 +100,7 @@ class UpdateTransformControl extends TransformControlBase<UpdateTransformControl
 
 class TransformUpdaterControl extends PluginUIComponent<{ nodeRef: string, initiallyCollapsed?: boolean, header?: StateTransformer.Definition['display'] }> {
     componentDidMount() {
-        this.subscribe(this.plugin.events.state.object.updated, ({ ref, state }) => {
+        this.subscribe(this.plugin.state.events.object.updated, ({ ref, state }) => {
             if (this.props.nodeRef !== ref || this.plugin.state.data !== state) return;
             this.forceUpdate();
         });

+ 2 - 2
src/mol-plugin-ui/structure/components.tsx

@@ -218,7 +218,7 @@ class StructureComponentGroup extends PurePluginUIComponent<{ group: StructureCo
     }
 
     componentDidMount() {
-        this.subscribe(this.plugin.events.state.cell.stateUpdated, e => {
+        this.subscribe(this.plugin.state.events.cell.stateUpdated, e => {
             if (State.ObjectEvent.isCell(e, this.pivot.cell)) this.forceUpdate();
         });
     }
@@ -378,7 +378,7 @@ class StructureRepresentationEntry extends PurePluginUIComponent<{ group: Struct
     }
 
     componentDidMount() {
-        this.subscribe(this.plugin.events.state.cell.stateUpdated, e => {
+        this.subscribe(this.plugin.state.events.cell.stateUpdated, e => {
             if (State.ObjectEvent.isCell(e, this.props.representation.cell)) this.forceUpdate();
         });
     }

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

@@ -64,7 +64,7 @@ export class GenericEntry<T extends HierarchyRef> extends PurePluginUIComponent<
     state = { showOptions: false }
 
     componentDidMount() {
-        this.subscribe(this.plugin.events.state.cell.stateUpdated, e => {
+        this.subscribe(this.plugin.state.events.cell.stateUpdated, e => {
             if (State.ObjectEvent.isCell(e, this.pivot?.cell)) this.forceUpdate();
         });
     }

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

@@ -211,7 +211,7 @@ class MeasurementEntry extends PurePluginUIComponent<{ cell: StructureMeasuremen
     state = { showUpdate: false }
 
     componentDidMount() {
-        this.subscribe(this.plugin.events.state.cell.stateUpdated, e => {
+        this.subscribe(this.plugin.state.events.cell.stateUpdated, e => {
             this.forceUpdate();
         });
     }

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

@@ -41,7 +41,7 @@ export class VolumeStreamingControls extends CollapsableControls<{}, VolumeStrea
                 description: StructureHierarchyManager.getSelectedStructuresDescription(this.plugin)
             });
         });
-        this.subscribe(this.plugin.events.state.cell.stateUpdated, e => {
+        this.subscribe(this.plugin.state.events.cell.stateUpdated, e => {
             if (StateTransform.hasTag(e.cell.transform, VolumeStreaming.RootTag)) this.forceUpdate();
         });
         this.subscribe(this.plugin.behaviors.state.isBusy, v => {

+ 2 - 2
src/mol-plugin/behavior/dynamic/representation.ts

@@ -145,10 +145,10 @@ export const SelectLoci = PluginBehavior.create({
             });
             this.ctx.managers.interactivity.lociSelects.addProvider(this.lociMarkProvider);
 
-            this.subscribeObservable(this.ctx.events.state.object.created, ({ ref }) => this.applySelectMark(ref));
+            this.subscribeObservable(this.ctx.state.events.object.created, ({ ref }) => this.applySelectMark(ref));
 
             // re-apply select-mark to all representation of an updated structure
-            this.subscribeObservable(this.ctx.events.state.object.updated, ({ ref }) => {
+            this.subscribeObservable(this.ctx.state.events.object.updated, ({ ref }) => {
                 const cell = this.ctx.state.data.cells.get(ref);
                 if (cell && SO.Molecule.Structure.is(cell.obj)) {
                     const reprs = this.ctx.state.data.select(StateSelection.Generators.ofType(SO.Molecule.Structure.Representation3D, ref));

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

@@ -221,14 +221,14 @@ export namespace VolumeStreaming {
         register(ref: string): void {
             this.ref = ref;
 
-            this.subscribeObservable(this.plugin.events.state.object.removed, o => {
+            this.subscribeObservable(this.plugin.state.events.object.removed, o => {
                 if (!PluginStateObject.Molecule.Structure.is(o.obj) || !StructureElement.Loci.is(this.lastLoci)) return;
                 if (this.lastLoci.structure === o.obj.data) {
                     this.lastLoci = EmptyLoci;
                 }
             });
 
-            this.subscribeObservable(this.plugin.events.state.object.updated, o => {
+            this.subscribeObservable(this.plugin.state.events.object.updated, o => {
                 if (!PluginStateObject.Molecule.Structure.is(o.oldObj) || !StructureElement.Loci.is(this.lastLoci)) return;
                 if (this.lastLoci.structure === o.oldObj.data) {
                     this.lastLoci = EmptyLoci;

+ 3 - 3
src/mol-plugin/behavior/static/state.ts

@@ -30,17 +30,17 @@ export function registerDefault(ctx: PluginContext) {
 }
 
 export function SyncBehaviors(ctx: PluginContext) {
-    ctx.events.state.object.created.subscribe(o => {
+    ctx.state.events.object.created.subscribe(o => {
         if (!SO.isBehavior(o.obj)) return;
         o.obj.data.register(o.ref);
     });
 
-    ctx.events.state.object.removed.subscribe(o => {
+    ctx.state.events.object.removed.subscribe(o => {
         if (!SO.isBehavior(o.obj)) return;
         o.obj.data.unregister();
     });
 
-    ctx.events.state.object.updated.subscribe(o => {
+    ctx.state.events.object.updated.subscribe(o => {
         if (o.action === 'recreate') {
             if (o.oldObj && SO.isBehavior(o.oldObj)) o.oldObj.data.unregister();
             if (o.obj && SO.isBehavior(o.obj)) o.obj.data.register(o.ref);

+ 2 - 14
src/mol-plugin/context.ts

@@ -69,18 +69,6 @@ export class PluginContext {
     readonly commands = new PluginCommandManager();
 
     readonly events = {
-        state: {
-            cell: {
-                stateUpdated: merge(this.state.data.events.cell.stateUpdated, this.state.behaviors.events.cell.stateUpdated),
-                created: merge(this.state.data.events.cell.created, this.state.behaviors.events.cell.created),
-                removed: merge(this.state.data.events.cell.removed, this.state.behaviors.events.cell.removed),
-            },
-            object: {
-                created: merge(this.state.data.events.object.created, this.state.behaviors.events.object.created),
-                removed: merge(this.state.data.events.object.removed, this.state.behaviors.events.object.removed),
-                updated: merge(this.state.data.events.object.updated, this.state.behaviors.events.object.updated)
-            }
-        },
         log: this.ev<LogEntry>(),
         task: this.tasks.events,
         canvas3d: {
@@ -246,8 +234,8 @@ export class PluginContext {
         this.tasks.dispose();
         this.layout.dispose();
 
-        objectForEach(this.managers, m => (m as any).dispose?.());
-        objectForEach(this.managers.structure, m => (m as any).dispose?.());
+        objectForEach(this.managers, m => (m as any)?.dispose?.());
+        objectForEach(this.managers.structure, m => (m as any)?.dispose?.());
 
         this.disposed = true;
     }

+ 14 - 0
src/mol-plugin/state.ts

@@ -16,6 +16,7 @@ import { UUID } from '../mol-util';
 import { InteractivityManager } from '../mol-plugin-state/manager/interactivity';
 import { produce } from 'immer';
 import { StructureFocusSnapshot } from '../mol-plugin-state/manager/structure/focus';
+import { merge } from 'rxjs';
 
 export { PluginState };
 
@@ -25,6 +26,19 @@ class PluginState {
     readonly data: State;
     readonly behaviors: State;
 
+    readonly events = {
+        cell: {
+            stateUpdated: merge(this.data.events.cell.stateUpdated, this.behaviors.events.cell.stateUpdated),
+            created: merge(this.data.events.cell.created, this.behaviors.events.cell.created),
+            removed: merge(this.data.events.cell.removed, this.behaviors.events.cell.removed),
+        },
+        object: {
+            created: merge(this.data.events.object.created, this.behaviors.events.object.created),
+            removed: merge(this.data.events.object.removed, this.behaviors.events.object.removed),
+            updated: merge(this.data.events.object.updated, this.behaviors.events.object.updated)
+        }
+    } as const
+
     getSnapshot(params?: PluginState.GetSnapshotParams): PluginState.Snapshot {
         const p = { ...PluginState.DefaultGetSnapshotParams, ...params };
         return {