Ver Fonte

mol-state: wip

David Sehnal há 6 anos atrás
pai
commit
60e43d0aef

+ 0 - 12
src/mol-state/model/reconcile.ts

@@ -1,12 +0,0 @@
-/**
- * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
- *
- * @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
-}

+ 6 - 2
src/mol-state/model/object.ts → src/mol-state/object.ts

@@ -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' }
 }

+ 15 - 0
src/mol-state/state.ts

@@ -0,0 +1,15 @@
+/**
+ * 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[]
+}

+ 7 - 4
src/mol-state/tree/transformer.ts → src/mol-state/transformer.ts

@@ -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,
 

+ 7 - 0
src/mol-state/transformer/manager.ts

@@ -0,0 +1,7 @@
+/**
+ * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
+ *
+ * @author David Sehnal <david.sehnal@gmail.com>
+ */
+
+// TODO: index for registered transformers

+ 7 - 0
src/mol-state/tree/action.ts

@@ -0,0 +1,7 @@
+/**
+ * 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

+ 1 - 3
src/mol-state/model/tree.ts → src/mol-state/tree/transation.ts

@@ -4,6 +4,4 @@
  * @author David Sehnal <david.sehnal@gmail.com>
  */
 
-export interface ModelTree {
-
-}
+// TODO

+ 12 - 6
src/mol-state/tree/transform.ts

@@ -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
+    }
 }

+ 2 - 0
src/mol-state/util/immutable-tree.ts

@@ -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.