Skip to content
Snippets Groups Projects
Commit d99b5bd5 authored by David Sehnal's avatar David Sehnal
Browse files

mol-state: throw error when trying to reuse StateBuilder

parent 6312c1f9
No related branches found
No related tags found
No related merge requests found
......@@ -249,6 +249,11 @@ class State {
if (!this.inTransaction) this.behaviors.isUpdating.next(true);
try {
if (StateBuilder.is(tree)) {
if (tree.editInfo.applied) throw new Error('This builder has already been applied. Create a new builder for further state updates');
tree.editInfo.applied = true;
}
this.reverted = false;
const ret = options && (options.revertIfAborted || options.revertOnError)
? await this._revertibleTreeUpdate(taskCtx, params, options)
......
......@@ -21,6 +21,7 @@ interface StateBuilder {
namespace StateBuilder {
export interface EditInfo {
applied: boolean,
sourceTree: StateTree,
count: number,
lastUpdate?: StateTransform.Ref
......@@ -108,7 +109,7 @@ namespace StateBuilder {
return this.state.state.runTask(this.state.state.updateTree(this, options));
}
constructor(tree: StateTree, state?: State) { this.state = { state, tree: tree.asTransient(), actions: [], editInfo: { sourceTree: tree, count: 0, lastUpdate: void 0 } } }
constructor(tree: StateTree, state?: State) { this.state = { state, tree: tree.asTransient(), actions: [], editInfo: { applied: false, sourceTree: tree, count: 0, lastUpdate: void 0 } } }
}
export class To<A extends StateObject, T extends StateTransformer = StateTransformer> implements StateBuilder {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment