From ad91027f96e23ec4d219e6a66dd9018a152aeeaf Mon Sep 17 00:00:00 2001
From: David Sehnal <david.sehnal@gmail.com>
Date: Mon, 4 Mar 2019 23:51:54 +0100
Subject: [PATCH] mol-plugin: apparently, awaiting a command inside command
 causes a deadlock

---
 src/mol-plugin/behavior/static/state.ts | 8 ++------
 src/mol-plugin/command.ts               | 2 --
 2 files changed, 2 insertions(+), 8 deletions(-)

diff --git a/src/mol-plugin/behavior/static/state.ts b/src/mol-plugin/behavior/static/state.ts
index e41e7e564..10e0cc596 100644
--- a/src/mol-plugin/behavior/static/state.ts
+++ b/src/mol-plugin/behavior/static/state.ts
@@ -135,10 +135,6 @@ export function Snapshots(ctx: PluginContext) {
     PluginCommands.State.Snapshots.Apply.subscribe(ctx, ({ id }) => {
         const snapshot = ctx.state.snapshots.setCurrent(id);
         if (!snapshot) return;
-        return PluginCommands.State.Snapshots.Set.dispatch(ctx, { snapshot });
-    });
-
-    PluginCommands.State.Snapshots.Set.subscribe(ctx, ({ snapshot }) => {
         return ctx.state.setSnapshot(snapshot);
     });
 
@@ -156,7 +152,7 @@ export function Snapshots(ctx: PluginContext) {
         const json = await ctx.runTask(ctx.fetch({ url, type: 'json' })); //  fetch(url, { referrer: 'no-referrer' });
         const snapshot = ctx.state.snapshots.setRemoteSnapshot(json.data);
         if (!snapshot) return;
-        return PluginCommands.State.Snapshots.Set.dispatch(ctx, { snapshot });
+        return ctx.state.setSnapshot(snapshot);
     });
 
     PluginCommands.State.Snapshots.DownloadToFile.subscribe(ctx, ({ name }) => {
@@ -174,7 +170,7 @@ export function Snapshots(ctx: PluginContext) {
         try {
             const data = await readFromFile(file, 'string').run();
             const snapshot = JSON.parse(data as string);
-            return PluginCommands.State.Snapshots.Set.dispatch(ctx, { snapshot });
+            return ctx.state.setSnapshot(snapshot);
         } catch (e) {
             ctx.log.error(`Reading JSON state: ${e}`);
         }
diff --git a/src/mol-plugin/command.ts b/src/mol-plugin/command.ts
index b373682d4..29e8929f1 100644
--- a/src/mol-plugin/command.ts
+++ b/src/mol-plugin/command.ts
@@ -33,8 +33,6 @@ export const PluginCommands = {
             Apply: PluginCommand<{ id: string }>({ isImmediate: true }),
             Clear: PluginCommand<{}>({ isImmediate: true }),
 
-            Set: PluginCommand<{ snapshot: PluginState.Snapshot }>(),
-
             Upload: PluginCommand<{ name?: string, description?: string, serverUrl: string }>({ isImmediate: true }),
             Fetch: PluginCommand<{ url: string }>(),
 
-- 
GitLab