Bladeren bron

mol-state: transaction rethrowErrors option

David Sehnal 4 jaren geleden
bovenliggende
commit
f392ac21cd
2 gewijzigde bestanden met toevoegingen van 4 en 2 verwijderingen
  1. 1 1
      src/mol-plugin/context.ts
  2. 3 1
      src/mol-state/state.ts

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

@@ -228,7 +228,7 @@ export class PluginContext {
         this.behaviors.interaction.selectionMode.next(mode);
     }
 
-    dataTransaction(f: (ctx: RuntimeContext) => Promise<void> | void, options?: { canUndo?: string | boolean }) {
+    dataTransaction(f: (ctx: RuntimeContext) => Promise<void> | void, options?: { canUndo?: string | boolean, rethrowErrors?: boolean }) {
         return this.runTask(this.state.data.transaction(f, options));
     }
 

+ 3 - 1
src/mol-state/state.ts

@@ -178,7 +178,7 @@ class State {
     private inTransactionError = false;
 
     /** Apply series of updates to the state. If any of them fail, revert to the original state. */
-    transaction(edits: (ctx: RuntimeContext) => Promise<void> | void, options?: { canUndo?: string | boolean }) {
+    transaction(edits: (ctx: RuntimeContext) => Promise<void> | void, options?: { canUndo?: string | boolean, rethrowErrors?: boolean }) {
         return Task.create('State Transaction', async ctx => {
             const isNested = this.inTransaction;
 
@@ -207,6 +207,8 @@ class State {
                     this.inTransactionError = true;
                     throw e;
                 }
+
+                if (options?.rethrowErrors) throw e;
             } finally {
                 if (!isNested) {
                     this.inTransaction = false;