From a9d20c7e92ae3d6b1a0509ebd97cc32e5dd226da Mon Sep 17 00:00:00 2001 From: David Sehnal <david.sehnal@gmail.com> Date: Mon, 18 Feb 2019 13:04:00 +0100 Subject: [PATCH] mol-state: generic StateObjectCell --- src/mol-state/object.ts | 4 ++-- src/mol-state/state/selection.ts | 2 +- src/mol-state/transformer.ts | 3 ++- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/mol-state/object.ts b/src/mol-state/object.ts index 3e2df3343..e8bdf7375 100644 --- a/src/mol-state/object.ts +++ b/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 { diff --git a/src/mol-state/state/selection.ts b/src/mol-state/state/selection.ts index 5bb6010f5..828f7c9cf 100644 --- a/src/mol-state/state/selection.ts +++ b/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 { diff --git a/src/mol-state/transformer.ts b/src/mol-state/transformer.ts index b10778f9f..3693eb5ca 100644 --- a/src/mol-state/transformer.ts +++ b/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'; -- GitLab