Skip to content
Snippets Groups Projects
Commit 3a22246e authored by David Sehnal's avatar David Sehnal
Browse files

mol-state: wip data model

parent cf97fbb0
No related branches found
No related tags found
No related merge requests found
......@@ -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"
},
......
/**
* 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
/**
* 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
/**
* 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
/**
* 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
/**
* 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
/**
* 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
/**
* 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
/**
* 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
/**
* 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
......@@ -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"]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment