Browse Source

added State.root and fix StateAction.createDefaultParams/.params

Alexander Rose 5 years ago
parent
commit
c9171444eb
3 changed files with 6 additions and 5 deletions
  1. 3 3
      src/apps/viewer/index.ts
  2. 2 2
      src/mol-state/action.ts
  3. 1 0
      src/mol-state/state.ts

+ 3 - 3
src/apps/viewer/index.ts

@@ -110,7 +110,7 @@ export class Viewer {
     }
 
     async loadStructureFromUrl(url: string, format = 'cif', isBinary = false) {
-        const params = DownloadStructure.createDefaultParams(undefined, this.plugin);
+        const params = DownloadStructure.createDefaultParams(this.plugin.state.data.root.obj!, this.plugin);
         return this.plugin.runTask(this.plugin.state.data.applyAction(DownloadStructure, {
             source: {
                 name: 'url',
@@ -125,7 +125,7 @@ export class Viewer {
     }
 
     async loadPdb(pdb: string) {
-        const params = DownloadStructure.createDefaultParams(undefined, this.plugin);
+        const params = DownloadStructure.createDefaultParams(this.plugin.state.data.root.obj!, this.plugin);
         const provider = this.plugin.config.get(PluginConfig.Download.DefaultPdbProvider)!;
         return this.plugin.runTask(this.plugin.state.data.applyAction(DownloadStructure, {
             source: {
@@ -145,7 +145,7 @@ export class Viewer {
     }
 
     async loadPdbDev(pdbDev: string) {
-        const params = DownloadStructure.createDefaultParams(undefined, this.plugin);
+        const params = DownloadStructure.createDefaultParams(this.plugin.state.data.root.obj!, this.plugin);
         return this.plugin.runTask(this.plugin.state.data.applyAction(DownloadStructure, {
             source: {
                 name: 'pdb-dev' as const,

+ 2 - 2
src/mol-state/action.ts

@@ -19,7 +19,7 @@ interface StateAction<A extends StateObject = StateObject, T = any, P extends {}
     readonly id: UUID,
     readonly definition: StateAction.Definition<A, T, P>,
     /** create a fresh copy of the params which can be edited in place */
-    createDefaultParams(a: A | undefined, globalCtx: unknown): P
+    createDefaultParams(a: A, globalCtx: unknown): P
 }
 
 namespace StateAction {
@@ -54,7 +54,7 @@ namespace StateAction {
     export interface Definition<A extends StateObject = StateObject, T = any, P extends {} = {}> extends DefinitionBase<A, T, P> {
         readonly from: StateObject.Ctor[],
         readonly display: { readonly name: string, readonly description?: string },
-        params?(a: A | undefined, globalCtx: unknown): { [K in keyof P]: PD.Any }
+        params?(a: A, globalCtx: unknown): { [K in keyof P]: PD.Any }
     }
 
     export function create<A extends StateObject, T, P extends {} = {}>(definition: Definition<A, T, P>): StateAction<A, T, P> {

+ 1 - 0
src/mol-state/state.ts

@@ -63,6 +63,7 @@ class State {
     get tree(): StateTree { return this._tree; }
     get transforms() { return (this._tree as StateTree).transforms; }
     get current() { return this.behaviors.currentObject.value.ref; }
+    get root() { return this.cells.get((this._tree as StateTree).root.ref)!; }
 
     build() { return new StateBuilder.Root(this.tree, this); }