Browse Source

StructureViewerState helper

Alexander Rose 5 years ago
parent
commit
723d1673ab

+ 1 - 1
src/structure-viewer/helpers/model.ts

@@ -11,7 +11,7 @@ import { PresetProps, RcsbPreset } from './preset';
 
 export class ModelLoader {
     get customState() {
-        return this.plugin.customState as StructureViewerState
+        return StructureViewerState(this.plugin)
     }
 
     async clear() {

+ 0 - 1
src/structure-viewer/index.html

@@ -67,7 +67,6 @@
         <script>
             function loadExample(index) {
                 var e = examples[index]
-                console.log(e)
                 viewer.loadPdbId(e.id, e.props)
             }
 

+ 4 - 0
src/structure-viewer/types.ts

@@ -5,6 +5,7 @@
  */
 
 import { ModelLoader } from './helpers/model';
+import { PluginContext } from 'molstar/lib/mol-plugin/context';
 
 export type ModelUrlProvider = (pdbId: string) => {
         url: string,
@@ -28,4 +29,7 @@ export interface LoadParams {
 export interface StructureViewerState {
     props: StructureViewerProps
     modelLoader: ModelLoader
+}
+export function StructureViewerState(plugin: PluginContext) {
+    return plugin.customState as StructureViewerState
 }

+ 1 - 1
src/structure-viewer/ui/controls.tsx

@@ -38,7 +38,7 @@ export class StructureTools extends PluginUIComponent {
 
 export class ControlsWrapper extends PluginUIComponent {
     get customState() {
-        return this.plugin.customState as StructureViewerState
+        return StructureViewerState(this.plugin)
     }
 
     render() {

+ 1 - 1
src/structure-viewer/ui/open.tsx

@@ -27,7 +27,7 @@ const OpenFileAction = StateAction.build({
     if (params.file.type !== 'cif' && params.file.type !== 'bcif') {
         throw new Error(`unsupported file format '${params.file.type}`)
     }
-    await (ctx.customState as StructureViewerState).modelLoader.load({ fileOrUrl: params.file, format: params.file.type, })
+    await StructureViewerState(ctx).modelLoader.load({ fileOrUrl: params.file, format: params.file.type, })
 }));
 
 export class OpenFile extends PluginUIComponent<{ initiallyCollapsed?: boolean }> {