Переглянути джерело

mol-state: fix dependent transform delete

David Sehnal 5 роки тому
батько
коміт
3643bd04f1

+ 1 - 1
src/mol-plugin/state/transforms/model.ts

@@ -715,7 +715,7 @@ const MultiStructureSelection = PluginStateTransform.BuiltIn({
 
         console.log(loci);
 
-        const props = { label: `${params.label || 'Multi-selection'}`, description: `${params.selections} source(s), ${size} element(s) total` };
+        const props = { label: `${params.label || 'Multi-selection'}`, description: `${params.selections.length} source(s), ${size} element(s) total` };
         return new SO.Molecule.Structure.Selections(loci, props);
     },
     // TODO: implement this

+ 19 - 8
src/mol-state/tree/transient.ts

@@ -215,27 +215,38 @@ class TransientTree implements StateTree {
         this.changeNodes();
         this.changeChildren();
 
+
         for (const n of st) {
             this.transforms.delete(n.ref);
             this.children.delete(n.ref);
             if (this._childMutations) this._childMutations.delete(n.ref);
+        }
+
+        const depRemoves: StateTransform[] = [];
+        for (const n of st) {
+
+            if (n.dependsOn) {
+                for (const d of n.dependsOn) {
+                    if (!this.transforms.has(d)) continue;
+                    this.mutateDependency(d, n.ref, 'remove');
+                }
+            }
 
             if (this.dependencies.has(n.ref)) {
+                const deps = this.dependencies.get(n.ref).toArray();
                 this.changeDependencies();
                 this.dependencies.delete(n.ref);
                 if (this._dependencyMutations) this._dependencyMutations.delete(n.ref);
-            }
-        }
 
-        for (const n of st) {
-            if (!n.dependsOn) continue;
-
-            for (const d of n.dependsOn) {
-                if (!this.transforms.has(d)) continue;
-                this.mutateDependency(d, n.ref, 'remove');
+                for (const dep of deps) {
+                    if (!this.transforms.has(dep)) continue;
+                    for (const del of this.remove(dep)) depRemoves[depRemoves.length] = del;
+                }
             }
         }
 
+        for (const dep of depRemoves) st[st.length] = dep;
+
         return st;
     }