Browse Source

mol-state: "silent" update

David Sehnal 6 years ago
parent
commit
6371d95eb8
2 changed files with 10 additions and 5 deletions
  1. 1 1
      src/mol-plugin/context.ts
  2. 9 4
      src/mol-state/state.ts

+ 1 - 1
src/mol-plugin/context.ts

@@ -146,7 +146,7 @@ export class PluginContext {
             tree.toRoot().apply(b.transformer, b.defaultParams, { ref: b.transformer.id });
         }
 
-        await this.runTask(this.state.behaviorState.update(tree));
+        await this.runTask(this.state.behaviorState.update(tree, true));
     }
 
     initDataActions() {

+ 9 - 4
src/mol-state/state.ts

@@ -118,7 +118,7 @@ class State {
         });
     }
 
-    update(tree: StateTree | StateTreeBuilder): Task<void> {
+    update(tree: StateTree | StateTreeBuilder, silent: boolean = false): Task<void> {
         const _tree = (StateTreeBuilder.is(tree) ? tree.getTree() : tree).asTransient();
         return Task.create('Update Tree', async taskCtx => {
             let updated = false;
@@ -139,6 +139,8 @@ class State {
 
                     results: [],
 
+                    silent,
+
                     changed: false,
                     hadError: false,
                     newCurrent: void 0
@@ -209,6 +211,9 @@ interface UpdateContext {
 
     results: UpdateNodeResult[],
 
+    // suppress timing messages
+    silent: boolean,
+
     changed: boolean,
     hadError: boolean,
     newCurrent?: Ref
@@ -492,13 +497,13 @@ async function updateSubtree(ctx: UpdateContext, root: Ref) {
         ctx.results.push(update);
         if (update.action === 'created') {
             isNull = update.obj === StateObject.Null;
-            if (!isNull) ctx.parent.events.log.next(LogEntry.info(`Created ${update.obj.label} in ${formatTimespan(time)}.`));
+            if (!isNull && !ctx.silent) ctx.parent.events.log.next(LogEntry.info(`Created ${update.obj.label} in ${formatTimespan(time)}.`));
         } else if (update.action === 'updated') {
             isNull = update.obj === StateObject.Null;
-            if (!isNull) ctx.parent.events.log.next(LogEntry.info(`Updated ${update.obj.label} in ${formatTimespan(time)}.`));
+            if (!isNull && !ctx.silent) ctx.parent.events.log.next(LogEntry.info(`Updated ${update.obj.label} in ${formatTimespan(time)}.`));
         } else if (update.action === 'replaced') {
             isNull = update.obj === StateObject.Null;
-            if (!isNull) ctx.parent.events.log.next(LogEntry.info(`Updated ${update.obj.label} in ${formatTimespan(time)}.`));
+            if (!isNull && !ctx.silent) ctx.parent.events.log.next(LogEntry.info(`Updated ${update.obj.label} in ${formatTimespan(time)}.`));
         }
     } catch (e) {
         ctx.changed = true;