Browse Source

mol-state: refactored transform state handling

David Sehnal 6 years ago
parent
commit
e13df4dc9f
2 changed files with 14 additions and 4 deletions
  1. 7 4
      src/mol-plugin/ui/state/tree.tsx
  2. 7 0
      src/mol-state/transform.ts

+ 7 - 4
src/mol-plugin/ui/state/tree.tsx

@@ -53,9 +53,10 @@ class StateTreeNode extends PluginUIComponent<{ cell: StateObjectCell, depth: nu
     componentDidMount() {
         this.subscribe(this.plugin.events.state.cell.stateUpdated, e => {
             if (this.props.cell === e.cell && this.is(e) && e.state.cells.has(this.ref)) {
-                if (!!this.props.cell.state.isCollapsed !== this.state.isCollapsed) {
-                    this.setState({ isCollapsed: !!e.cell.state.isCollapsed });
-                }
+                this.forceUpdate();
+                // if (!!this.props.cell.state.isCollapsed !== this.state.isCollapsed) {
+                //     this.setState({ isCollapsed: !!e.cell.state.isCollapsed });
+                // }
             }
         });
 
@@ -83,7 +84,9 @@ class StateTreeNode extends PluginUIComponent<{ cell: StateObjectCell, depth: nu
 
     render() {
         const cell = this.props.cell;
-        if (!cell || cell.obj === StateObject.Null) return null;
+        if (!cell || cell.obj === StateObject.Null) {
+            return null;
+        }
 
         const cellState = cell.state;
         const showLabel = cell.status !== 'ok' || !cell.state.isGhost;

+ 7 - 0
src/mol-state/transform.ts

@@ -52,6 +52,7 @@ namespace Transform {
 
     export function assignState(a: State, b?: Partial<State>): boolean {
         if (!b) return false;
+
         let changed = false;
         for (const k of Object.keys(b)) {
             const s = (b as any)[k], t = (a as any)[k];
@@ -59,6 +60,12 @@ namespace Transform {
             changed = true;
             (a as any)[k] = s;
         }
+        for (const k of Object.keys(a)) {
+            const s = (b as any)[k], t = (a as any)[k];
+            if (!!s === !!t) continue;
+            changed = true;
+            (a as any)[k] = s;
+        }
         return changed;
     }