Browse Source

mol-plugin: apparently, awaiting a command inside command causes a deadlock

David Sehnal 6 years ago
parent
commit
ad91027f96
2 changed files with 2 additions and 8 deletions
  1. 2 6
      src/mol-plugin/behavior/static/state.ts
  2. 0 2
      src/mol-plugin/command.ts

+ 2 - 6
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}`);
         }

+ 0 - 2
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 }>(),