diff --git a/package.json b/package.json index 33864e84fe59b94d88a97e2ee7a7ae159ee4661e..560a898538bc016a00b543be2f43799e74a198ab 100644 --- a/package.json +++ b/package.json @@ -60,6 +60,7 @@ "mol-ql($|/.*)": "<rootDir>/src/mol-ql$1", "mol-script($|/.*)": "<rootDir>/src/mol-script$1", "mol-task($|/.*)": "<rootDir>/src/mol-task$1", + "mol-state($|/.*)": "<rootDir>/src/mol-state$1", "mol-util($|/.*)": "<rootDir>/src/mol-util$1", "mol-view($|/.*)": "<rootDir>/src/mol-view$1" }, diff --git a/src/mol-state/context/context.ts b/src/mol-state/context/context.ts new file mode 100644 index 0000000000000000000000000000000000000000..b7fd34c4cb9e8389d55489c8b0b5c8b8330307ab --- /dev/null +++ b/src/mol-state/context/context.ts @@ -0,0 +1,9 @@ +/** + * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info. + * + * @author David Sehnal <david.sehnal@gmail.com> + */ + +export interface StateContext { + +} \ No newline at end of file diff --git a/src/mol-state/context/event.ts b/src/mol-state/context/event.ts new file mode 100644 index 0000000000000000000000000000000000000000..32dcb9a0516c288ed83911bba462598e0372cb0d --- /dev/null +++ b/src/mol-state/context/event.ts @@ -0,0 +1,9 @@ +/** + * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info. + * + * @author David Sehnal <david.sehnal@gmail.com> + */ + +export interface EventDispatcher { + // TODO +} \ No newline at end of file diff --git a/src/mol-state/index.ts b/src/mol-state/index.ts new file mode 100644 index 0000000000000000000000000000000000000000..9dd0621de618c2a038d9e82f08cf9e6be0f0f843 --- /dev/null +++ b/src/mol-state/index.ts @@ -0,0 +1,5 @@ +/** + * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info. + * + * @author David Sehnal <david.sehnal@gmail.com> + */ \ No newline at end of file diff --git a/src/mol-state/model/node.ts b/src/mol-state/model/node.ts new file mode 100644 index 0000000000000000000000000000000000000000..cd4807c6099ee872736ea5c393738306a2fbfecc --- /dev/null +++ b/src/mol-state/model/node.ts @@ -0,0 +1,17 @@ +/** + * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info. + * + * @author David Sehnal <david.sehnal@gmail.com> + */ + +export interface ModelNode<T = any> { + '@type': T +} + +export namespace ModelNode { + export type TypeOf<T> + = T extends ModelNode<infer X> ? [X] + : T extends [ModelNode<infer X>] ? [X] + : T extends [ModelNode<infer X>, ModelNode<infer Y>] ? [X, Y] + : unknown[]; +} \ No newline at end of file diff --git a/src/mol-state/model/reconcile.ts b/src/mol-state/model/reconcile.ts new file mode 100644 index 0000000000000000000000000000000000000000..95997d7ce17b6542bc5affedddc9f4608cb7ebe2 --- /dev/null +++ b/src/mol-state/model/reconcile.ts @@ -0,0 +1,12 @@ +/** + * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info. + * + * @author David Sehnal <david.sehnal@gmail.com> + */ + +import { TransformTree } from '../transform/tree'; +import { ModelTree } from './tree'; + +export function reconcileTree(transform: TransformTree, model: ModelTree, root?: number) { + // TODO +} \ No newline at end of file diff --git a/src/mol-state/model/tree.ts b/src/mol-state/model/tree.ts new file mode 100644 index 0000000000000000000000000000000000000000..601f3be436a94cecc04d6e7baba1af1fbf776b26 --- /dev/null +++ b/src/mol-state/model/tree.ts @@ -0,0 +1,9 @@ +/** + * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info. + * + * @author David Sehnal <david.sehnal@gmail.com> + */ + +export interface ModelTree { + +} \ No newline at end of file diff --git a/src/mol-state/transform/transform.ts b/src/mol-state/transform/transform.ts new file mode 100644 index 0000000000000000000000000000000000000000..7234fd6fc1c26fc91beba2004c5c77ae7e153fd8 --- /dev/null +++ b/src/mol-state/transform/transform.ts @@ -0,0 +1,27 @@ +/** + * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info. + * + * @author David Sehnal <david.sehnal@gmail.com> + */ + +import { Transform } from './transform'; +import { ModelNode } from '../model/node'; +import { Transformer } from './transformer'; + +export interface Transform<A extends ModelNode, B extends ModelNode, P = any> { + readonly instanceId: number, + + readonly transformer: Transformer<A, B, P>, + readonly props: Transform.Props, + + readonly transformerId: string, + readonly params: P, + readonly ref: string, + readonly version: number, +} + +export namespace Transform { + export interface Props { + + } +} \ No newline at end of file diff --git a/src/mol-state/transform/transformer.ts b/src/mol-state/transform/transformer.ts new file mode 100644 index 0000000000000000000000000000000000000000..2717105428e663f42d51d9cbaf8eff3f95aa65b7 --- /dev/null +++ b/src/mol-state/transform/transformer.ts @@ -0,0 +1,69 @@ +/** + * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info. + * + * @author David Sehnal <david.sehnal@gmail.com> + */ + +import { Task } from 'mol-task'; +import { EventDispatcher } from '../context/event'; +import { ModelNode } from '../model/node'; +import { ModelTree } from '../model/tree'; + +export interface Transformer<A extends ModelNode, B extends ModelNode, P = any> { + readonly id: Transformer.Id, + readonly definition: Transformer.Definition<A, B, P> +} + +export namespace Transformer { + export type Id = string & { '@type': 'transformer-id' } + export type Params<T extends Transformer<any, any, any>> = T extends Transformer<any, any, infer P> ? P : unknown; + + export interface Definition<A extends ModelNode, B extends ModelNode, P> { + readonly name: string, + readonly namespace: string, + readonly description?: string, + readonly from: ModelNode.TypeOf<A>[], + readonly to: ModelNode.TypeOf<B>[] + + /** + * Apply the actual transformation. It must be pure (i.e. with no side effects). + * Returns a task that produces the result of the result directly. + */ + apply(a: A, params: P, context: TransformContext): Task<B> | B, + + /** + * Attempts to update the entity in a non-destructive way. + * For example changing a color scheme of a visual does not require computing new geometry. + * Return/resolve to undefined if the update is not possible. + * + * The ability to resolve the task to undefined is present for "async updates" (i.e. containing an ajax call). + */ + update?(a: A, b: B, newParams: P, context: TransformContext): Task<B | undefined> | B | undefined, + + /** Check the parameters and return a list of errors if the are not valid. */ + defaultParams?(a: A, context: TransformContext): P, + + /** */ + defaultControls?(a: A, context: TransformContext): ControlsFor<P>, + + /** Check the parameters and return a list of errors if the are not valid. */ + validateParams?(a: A, params: P, context: TransformContext): string[] | undefined, + + /** Test if the transform can be applied to a given node */ + isApplicable?(a: A, context: TransformContext): boolean, + + /** By default, returns true */ + isSerializable?(params: P): { isSerializable: true } | { isSerializable: false; reason: string }, + } + + export type ControlsFor<Props> = { [P in keyof Props]: any } + + /** A tree context constructed dynamically duing application of transforms. */ + export interface TransformContext { + /** An event dispatcher for executing child tasks. */ + dispatcher: EventDispatcher, + + globalContext: any, + tree: ModelTree + } +} \ No newline at end of file diff --git a/src/mol-state/transform/tree.ts b/src/mol-state/transform/tree.ts new file mode 100644 index 0000000000000000000000000000000000000000..ee9863182de55f06a85876fb6e2860c6b1eea213 --- /dev/null +++ b/src/mol-state/transform/tree.ts @@ -0,0 +1,17 @@ +/** + * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info. + * + * @author David Sehnal <david.sehnal@gmail.com> + */ + +export interface TransformTree { + // TODO +} + +export namespace TransformTree { + export interface Update { + readonly tree: TransformTree, + readonly rootId: number, + readonly params: unknown + } +} \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index 413bfe5853cfed2ef8b0fe98eea7593d816baa03..aa0ec9bccf5a879ebbe430882ff53c45c66993dd 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -24,6 +24,7 @@ "mol-model-props": ["./mol-model-props", "./mol-model-props/index.ts"], "mol-ql": ["./mol-ql"], "mol-script": ["./mol-script"], + "mol-state": ["./mol-state", "./mol-state/index.ts"], "mol-task": ["./mol-task", "./mol-task/index.ts"], "mol-util": ["./mol-util", "./mol-util/index.ts"], "mol-view": ["./mol-view"]