From ab183d9c52717dcf26a46d3fbac736772af1670e Mon Sep 17 00:00:00 2001
From: David Sehnal <david.sehnal@gmail.com>
Date: Fri, 9 Nov 2018 14:03:48 +0100
Subject: [PATCH] mol-state: wip

---
 src/mol-state/context.ts |  6 +++---
 src/mol-state/object.ts  | 11 ++++++-----
 src/mol-state/state.ts   | 18 +++++++++---------
 3 files changed, 18 insertions(+), 17 deletions(-)

diff --git a/src/mol-state/context.ts b/src/mol-state/context.ts
index ff471db4e..be61abb32 100644
--- a/src/mol-state/context.ts
+++ b/src/mol-state/context.ts
@@ -34,15 +34,15 @@ class StateContext {
     };
 
     readonly globalContext: unknown;
-    readonly defaultObjectProps: unknown;
+    readonly defaultCellState: unknown;
 
     dispose() {
         this.ev.dispose();
     }
 
-    constructor(params: { globalContext: unknown, defaultObjectProps: unknown, rootRef: Transform.Ref }) {
+    constructor(params: { globalContext: unknown, defaultCellState: unknown, rootRef: Transform.Ref }) {
         this.globalContext = params.globalContext;
-        this.defaultObjectProps = params.defaultObjectProps;
+        this.defaultCellState = params.defaultCellState;
         this.behaviors.currentObject.next({ ref: params.rootRef });
     }
 }
\ No newline at end of file
diff --git a/src/mol-state/object.ts b/src/mol-state/object.ts
index fcd4581ec..14f759114 100644
--- a/src/mol-state/object.ts
+++ b/src/mol-state/object.ts
@@ -37,18 +37,19 @@ namespace StateObject {
 
 interface StateObjectCell {
     ref: Transform.Ref,
-    props: unknown,
-
+    version: string
     status: StateObjectCell.Status,
+
+    state: unknown,
+
     errorText?: string,
-    obj?: StateObject,
-    version: string
+    obj?: StateObject
 }
 
 namespace StateObjectCell {
     export type Status = 'ok' | 'error' | 'pending' | 'processing'
 
-    export interface Props {
+    export interface State {
         isVisible: boolean,
         isHidden: boolean,
         isBound: boolean,
diff --git a/src/mol-state/state.ts b/src/mol-state/state.ts
index 70a40a532..f8f779a8e 100644
--- a/src/mol-state/state.ts
+++ b/src/mol-state/state.ts
@@ -33,7 +33,7 @@ class State {
             const key = keys.next();
             if (key.done) break;
             const o = this.cells.get(key.value)!;
-            props[key.value] = { ...o.props };
+            props[key.value] = { ...o.state };
         }
         return {
             tree: StateTree.toJSON(this._tree),
@@ -79,22 +79,22 @@ class State {
         });
     }
 
-    constructor(rootObject: StateObject, params?: { globalContext?: unknown, defaultObjectProps?: unknown }) {
+    constructor(rootObject: StateObject, params?: { globalContext?: unknown, defaultCellState?: unknown }) {
         const tree = this._tree;
         const root = tree.getValue(tree.rootRef)!;
-        const defaultObjectProps = (params && params.defaultObjectProps) || { }
+        const defaultCellState = (params && params.defaultCellState) || { }
 
         this.cells.set(tree.rootRef, {
             ref: tree.rootRef,
             obj: rootObject,
             status: 'ok',
             version: root.version,
-            props: { ...defaultObjectProps }
+            state: { ...defaultCellState }
         });
 
         this.context = new StateContext({
             globalContext: params && params.globalContext,
-            defaultObjectProps,
+            defaultCellState,
             rootRef: tree.rootRef
         });
     }
@@ -183,7 +183,7 @@ namespace State {
             obj.status = status;
             obj.errorText = errorText;
         } else {
-            const obj: StateObjectCell = { ref, status, version: UUID.create(), errorText, props: { ...ctx.stateCtx.defaultObjectProps } };
+            const obj: StateObjectCell = { ref, status, version: UUID.create(), errorText, state: { ...ctx.stateCtx.defaultCellState } };
             ctx.cells.set(ref, obj);
             changed = true;
         }
@@ -268,7 +268,7 @@ namespace State {
                 obj,
                 status: 'ok',
                 version: transform.version,
-                props: { ...ctx.stateCtx.defaultObjectProps, ...transform.defaultProps }
+                state: { ...ctx.stateCtx.defaultCellState, ...transform.defaultProps }
             });
             return { action: 'created', obj };
         } else {
@@ -288,13 +288,13 @@ namespace State {
                         obj,
                         status: 'ok',
                         version: transform.version,
-                        props: { ...ctx.stateCtx.defaultObjectProps, ...current.props, ...transform.defaultProps }
+                        state: { ...ctx.stateCtx.defaultCellState, ...current.state, ...transform.defaultProps }
                     });
                     return { action: 'replaced', oldObj: current.obj!, newObj: obj };
                 }
                 case Transformer.UpdateResult.Updated:
                     current.version = transform.version;
-                    current.props = { ...ctx.stateCtx.defaultObjectProps, ...current.props, ...transform.defaultProps };
+                    current.state = { ...ctx.stateCtx.defaultCellState, ...current.state, ...transform.defaultProps };
                     return { action: 'updated', obj: current.obj };
                 default:
                     // TODO check if props need to be updated
-- 
GitLab