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

mol-state: wip

parent b358c3ba
No related branches found
No related tags found
No related merge requests found
......@@ -4,9 +4,11 @@
* @author David Sehnal <david.sehnal@gmail.com>
*/
export interface StateObject<T = any> {
/** A mutable state object */
export interface StateObject<T extends StateObject.Type = any> {
'@type': T,
readonly label: string
label: string,
version: number
}
export namespace StateObject {
......@@ -26,4 +28,6 @@ export namespace StateObject {
// The object is currently being created
Processing
}
export type Type = string & { '@type': 'state-object-type' }
}
\ 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 { StateObject } from './object';
import { TransformTree } from './tree/tree';
import { Transform } from './tree/transform';
export interface State {
tree: TransformTree,
objects: Map<Transform.InstanceId, StateObject>,
history: TransformTree[]
}
\ No newline at end of file
......@@ -5,16 +5,16 @@
*/
import { Task } from 'mol-task';
import { StateObject } from '../model/object';
import { TransformContext } from './context';
import { StateObject } from './object';
import { TransformContext } from './tree/context';
export interface Transformer<A extends StateObject, B extends StateObject, P = any> {
readonly id: Transformer.Id,
readonly name: string,
readonly namespace: string,
readonly description?: string,
readonly from: StateObject.TypeOf<A>[],
readonly to: StateObject.TypeOf<B>[],
readonly from: StateObject.Type[],
readonly to: StateObject.Type[],
/**
* Apply the actual transformation. It must be pure (i.e. with no side effects).
......@@ -40,6 +40,9 @@ export interface Transformer<A extends StateObject, B extends StateObject, P = a
/** Check the parameters and return a list of errors if the are not valid. */
validateParams?(a: A, params: P, context: TransformContext): string[] | undefined,
/** Optional custom parameter equality. Use deep structural equal by default. */
areParamsEqual?(oldParams: P, newParams: P): boolean,
/** Test if the transform can be applied to a given node */
isApplicable?(a: A, context: TransformContext): boolean,
......
......@@ -4,9 +4,4 @@
* @author David Sehnal <david.sehnal@gmail.com>
*/
import { TransformTree } from '../tree/tree';
import { ModelTree } from './tree';
export function reconcileTree(transform: TransformTree, model: ModelTree, root?: number) {
// TODO
}
\ No newline at end of file
// TODO: index for registered transformers
\ 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>
*/
// TODO: tree actions: Add, Update, Delete; action queue
\ No newline at end of file
......@@ -4,6 +4,4 @@
* @author David Sehnal <david.sehnal@gmail.com>
*/
export interface ModelTree {
}
\ No newline at end of file
// TODO
\ No newline at end of file
......@@ -4,24 +4,30 @@
* @author David Sehnal <david.sehnal@gmail.com>
*/
import { Transform } from './transform';
import { StateObject } from '../model/object';
import { Transformer } from './transformer';
import { StateObject } from '../object';
import { Transformer } from '../transformer';
export interface Transform<A extends StateObject, B extends StateObject, P = any> {
readonly instanceId: number,
readonly instanceId: Transform.InstanceId,
readonly transformer: Transformer<A, B, P>,
readonly props: Transform.Props,
readonly transformerId: string,
readonly params: P,
readonly ref: string,
readonly version: number,
readonly ref: string
// version is part of the tree
}
export namespace Transform {
export type InstanceId = number & { '@type': 'transform-instance-id' }
export interface Props {
}
export enum Flags {
// Indicates that the transform was generated by a behaviour and should not be automatically updated
Generated
}
}
\ No newline at end of file
......@@ -6,6 +6,8 @@
import { Map as ImmutableMap, OrderedSet } from 'immutable';
// TODO: use generic "node keys" instead of string
/**
* An immutable tree where each node requires a unique reference.
* Represented as an immutable map.
......
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