Browse Source

mol-state: generic StateObjectCell

David Sehnal 6 years ago
parent
commit
a9d20c7e92
3 changed files with 5 additions and 4 deletions
  1. 2 2
      src/mol-state/object.ts
  2. 1 1
      src/mol-state/state/selection.ts
  3. 2 1
      src/mol-state/transformer.ts

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

@@ -53,7 +53,7 @@ namespace StateObject {
     };
 }
 
-interface StateObjectCell {
+interface StateObjectCell<T = StateObject> {
     transform: Transform,
 
     // Which object was used as a parent to create data in this cell
@@ -68,7 +68,7 @@ interface StateObjectCell {
     } | undefined;
 
     errorText?: string,
-    obj?: StateObject
+    obj?: T
 }
 
 namespace StateObjectCell {

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

@@ -29,7 +29,7 @@ namespace StateSelection {
     }
 
     function isObj(arg: any): arg is StateObjectCell {
-        return (arg as StateObjectCell).version !== void 0;
+        return (arg as StateObjectCell).version !== void 0 && (arg as StateObjectCell).transform !== void 0;
     }
 
     function isBuilder(arg: any): arg is Builder {

+ 2 - 1
src/mol-state/transformer.ts

@@ -5,7 +5,7 @@
  */
 
 import { Task } from 'mol-task';
-import { StateObject } from './object';
+import { StateObject, StateObjectCell } from './object';
 import { Transform } from './transform';
 import { ParamDefinition as PD } from 'mol-util/param-definition';
 import { StateAction } from './action';
@@ -24,6 +24,7 @@ export namespace Transformer {
     export type Params<T extends Transformer<any, any, any>> = T extends Transformer<any, any, infer P> ? P : unknown;
     export type From<T extends Transformer<any, any, any>> = T extends Transformer<infer A, any, any> ? A : unknown;
     export type To<T extends Transformer<any, any, any>> = T extends Transformer<any, infer B, any> ? B : unknown;
+    export type Cell<T extends Transformer<any, any, any>> = T extends Transformer<any, infer B, any> ? StateObjectCell<B> : unknown;
 
     export function is(obj: any): obj is Transformer {
         return !!obj && typeof (obj as Transformer).toAction === 'function' && typeof (obj as Transformer).apply === 'function';