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

mol-state: delete nodes starting from leaves

parent 3ea728bf
No related branches found
No related tags found
No related merge requests found
......@@ -165,16 +165,14 @@ namespace State {
return findState.roots;
}
type FindDeletesCtx = { newTree: StateTree, cells: State.Cells, deletes: Ref[] }
function _visitCheckDelete(n: ImmutableTree.Node<any>, _: any, ctx: FindDeletesCtx) {
if (!ctx.newTree.nodes.has(n.ref) && ctx.cells.has(n.ref)) ctx.deletes.push(n.ref);
}
function findDeletes(ctx: UpdateContext): Ref[] {
// TODO: do this in some sort of "tree order"?
const deletes: Ref[] = [];
const keys = ctx.cells.keys();
while (true) {
const key = keys.next();
if (key.done) break;
if (!ctx.tree.nodes.has(key.value)) deletes.push(key.value);
}
return deletes;
const deleteCtx: FindDeletesCtx = { newTree: ctx.tree, cells: ctx.cells, deletes: [] };
ImmutableTree.doPostOrder(ctx.oldTree, ctx.oldTree.nodes.get(ctx.oldTree.rootRef), deleteCtx, _visitCheckDelete);
return deleteCtx.deletes;
}
function setObjectState(ctx: UpdateContext, ref: Ref, status: StateObjectCell.Status, errorText?: string) {
......
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