From e13df4dc9f9e78156129cd79c44d67a498a4daa3 Mon Sep 17 00:00:00 2001
From: David Sehnal <david.sehnal@gmail.com>
Date: Tue, 26 Mar 2019 13:52:27 +0100
Subject: [PATCH] mol-state: refactored transform state handling

---
 src/mol-plugin/ui/state/tree.tsx | 11 +++++++----
 src/mol-state/transform.ts       |  7 +++++++
 2 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/src/mol-plugin/ui/state/tree.tsx b/src/mol-plugin/ui/state/tree.tsx
index 6bd6d173a..5e0815d2d 100644
--- a/src/mol-plugin/ui/state/tree.tsx
+++ b/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;
diff --git a/src/mol-state/transform.ts b/src/mol-state/transform.ts
index 5c99cbb04..0e11a042e 100644
--- a/src/mol-state/transform.ts
+++ b/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;
     }
 
-- 
GitLab