Explorar o código

QueryRuntimeTable.removeSymbol/CustomProp

David Sehnal %!s(int64=5) %!d(string=hai) anos
pai
achega
8c959f8a60

+ 1 - 2
src/extensions/rcsb/validation-report/behavior.ts

@@ -71,8 +71,7 @@ export const RCSBValidationReport = PluginBehavior.create<{ autoAttach: boolean,
         }
 
         unregister() {
-            // TODO
-            // DefaultQueryRuntimeTable.removeCustomProp(this.provider.descriptor);
+            DefaultQueryRuntimeTable.removeCustomProp(this.provider.descriptor);
 
             this.ctx.customStructureProperties.unregister(this.provider.descriptor.name);
 

+ 1 - 2
src/mol-plugin/behavior/dynamic/custom-props/computed/accessible-surface-area.ts

@@ -51,8 +51,7 @@ export const AccessibleSurfaceArea = PluginBehavior.create<{ autoAttach: boolean
         }
 
         unregister() {
-            // TODO
-            // DefaultQueryRuntimeTable.removeCustomProp(this.provider.descriptor);
+            DefaultQueryRuntimeTable.removeCustomProp(this.provider.descriptor);
 
             this.ctx.customStructureProperties.unregister(this.provider.descriptor.name);
             this.ctx.representation.structure.themes.colorThemeRegistry.remove(AccessibleSurfaceAreaColorThemeProvider);

+ 13 - 1
src/mol-script/runtime/query/base.ts

@@ -11,9 +11,13 @@ import { MSymbol } from '../../language/symbol';
 export class QueryRuntimeTable {
     private map = new Map<string, QuerySymbolRuntime>();
 
+    removeSymbol(runtime: QuerySymbolRuntime) {
+        this.map.delete(runtime.symbol.id);
+    }
+
     addSymbol(runtime: QuerySymbolRuntime) {
         if (this.map.has(runtime.symbol.id)) {
-            throw new Error(`Symbol '${runtime.symbol.id}' already added.`);
+            console.warn(`Symbol '${runtime.symbol.id}' already added. Call removeSymbol/removeCustomProps re-adding the symbol.`);
         }
         this.map.set(runtime.symbol.id, runtime);
     }
@@ -26,6 +30,14 @@ export class QueryRuntimeTable {
         }
     }
 
+    removeCustomProp(desc: CustomPropertyDescriptor<any>) {
+        if (!desc.symbols) return;
+
+        for (const k of Object.keys(desc.symbols)) {
+            this.removeSymbol((desc.symbols as any)[k]);
+        }
+    }
+
     getRuntime(id: string) {
         return this.map.get(id);
     }