Browse Source

mol-state: nested transactions

David Sehnal 5 năm trước cách đây
mục cha
commit
00cd54b69c
1 tập tin đã thay đổi với 8 bổ sung1 xóa
  1. 8 1
      src/mol-state/state.ts

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

@@ -132,10 +132,12 @@ class State {
     /** Apply series of updates to the state. If any of them fail, revert to the original state. */
     transaction(edits: () => Promise<void> | void) {
         return Task.create('State Transaction', async ctx => {
+            const isNested = this.inTransaction;
+
             const snapshot = this._tree.asImmutable();
             let restored = false;
             try {
-                this.events.isUpdating.next(true);
+                if (!isNested) this.events.isUpdating.next(true);
                 this.inTransaction = true;
                 await edits();
 
@@ -150,7 +152,12 @@ class State {
                     await this.updateTree(snapshot).runInContext(ctx);
                     this.events.log.error(e);
                 }
+                if (isNested) throw e;
             } finally {
+                if (isNested) {
+                    return;
+                }
+                
                 this.inTransaction = false;
                 this.events.changed.next({ state: this, inTransaction: false });
                 this.events.isUpdating.next(false);