From 8c959f8a604d01a6aad45e942deae6424f9acf05 Mon Sep 17 00:00:00 2001 From: David Sehnal <david.sehnal@gmail.com> Date: Wed, 22 Apr 2020 14:07:11 +0200 Subject: [PATCH] QueryRuntimeTable.removeSymbol/CustomProp --- src/extensions/rcsb/validation-report/behavior.ts | 3 +-- .../computed/accessible-surface-area.ts | 3 +-- src/mol-script/runtime/query/base.ts | 14 +++++++++++++- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/extensions/rcsb/validation-report/behavior.ts b/src/extensions/rcsb/validation-report/behavior.ts index 00b9d38fc..cf1d189ea 100644 --- a/src/extensions/rcsb/validation-report/behavior.ts +++ b/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); diff --git a/src/mol-plugin/behavior/dynamic/custom-props/computed/accessible-surface-area.ts b/src/mol-plugin/behavior/dynamic/custom-props/computed/accessible-surface-area.ts index 06bc52745..6d6be15f8 100644 --- a/src/mol-plugin/behavior/dynamic/custom-props/computed/accessible-surface-area.ts +++ b/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); diff --git a/src/mol-script/runtime/query/base.ts b/src/mol-script/runtime/query/base.ts index b9982624d..dabc80ad3 100644 --- a/src/mol-script/runtime/query/base.ts +++ b/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); } -- GitLab