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

mol-state: added StateObject.Null

parent 40aa847d
No related branches found
No related tags found
No related merge requests found
......@@ -6,7 +6,7 @@
import * as React from 'react';
import { PluginStateObject } from 'mol-plugin/state/objects';
import { State } from 'mol-state'
import { State, StateObject } from 'mol-state'
import { PluginCommands } from 'mol-plugin/command';
import { PluginComponent } from './base';
......@@ -60,6 +60,8 @@ class StateTreeNode extends PluginComponent<{ nodeRef: string, state: State }, {
}
render() {
if (this.props.state.cells.get(this.props.nodeRef)!.obj === StateObject.Null) return null;
const cellState = this.cellState;
const children = this.props.state.tree.children.get(this.props.nodeRef);
......
......@@ -9,7 +9,7 @@ import { Transform } from './transform';
export { StateObject, StateObjectCell }
interface StateObject<D = any, T extends StateObject.Type = { name: string, typeClass: any }> {
interface StateObject<D = any, T extends StateObject.Type = StateObject.Type<any>> {
readonly id: UUID,
readonly type: T,
readonly data: D,
......@@ -39,6 +39,14 @@ namespace StateObject {
}
}
}
/** A special object indicating a transformer result has no value. */
export const Null: StateObject<any, any> = {
id: UUID.create22(),
type: { name: 'Null', typeClass: 'Null' },
data: void 0,
label: 'Null'
};
}
interface StateObjectCell {
......
......@@ -441,6 +441,7 @@ type UpdateNodeResult =
async function updateSubtree(ctx: UpdateContext, root: Ref) {
setCellStatus(ctx, root, 'processing');
let isNull = false;
try {
const start = now();
const update = await updateNode(ctx, root);
......@@ -451,10 +452,13 @@ async function updateSubtree(ctx: UpdateContext, root: Ref) {
setCellStatus(ctx, root, 'ok');
ctx.results.push(update);
if (update.action === 'created') {
isNull = update.obj === StateObject.Null;
ctx.parent.events.log.next(LogEntry.info(`Created ${update.obj.label} in ${formatTimespan(time)}.`));
} else if (update.action === 'updated') {
isNull = update.obj === StateObject.Null;
ctx.parent.events.log.next(LogEntry.info(`Updated ${update.obj.label} in ${formatTimespan(time)}.`));
} else if (update.action === 'replaced') {
isNull = update.obj === StateObject.Null;
ctx.parent.events.log.next(LogEntry.info(`Updated ${update.obj.label} in ${formatTimespan(time)}.`));
}
} catch (e) {
......@@ -464,6 +468,10 @@ async function updateSubtree(ctx: UpdateContext, root: Ref) {
return;
}
// Do not continue the updates if the object is null
// TODO: set the states to something "nicer"?
if (isNull) return;
const children = ctx.tree.children.get(root).values();
while (true) {
const next = children.next();
......@@ -497,7 +505,7 @@ async function updateNode(ctx: UpdateContext, currentRef: Ref): Promise<UpdateNo
} else {
const oldParams = oldTree.transforms.get(currentRef)!.params;
const updateKind = !!current.obj
const updateKind = !!current.obj && current.obj !== StateObject.Null
? await updateObject(ctx, currentRef, transform.transformer, parent, current.obj!, oldParams, transform.params)
: Transformer.UpdateResult.Recreate;
......
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