Skip to content

Commit 56a1e02

Browse files
author
Oleksandr Dzhychko
committed
chore(bulk-model-sync-lib): add comments about child removal logic when moving children
1 parent 4b1b60d commit 56a1e02

File tree

1 file changed

+8
-0
lines changed
  • bulk-model-sync-lib/src/commonMain/kotlin/org/modelix/model/sync/bulk

1 file changed

+8
-0
lines changed

bulk-model-sync-lib/src/commonMain/kotlin/org/modelix/model/sync/bulk/ModelImporter.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,12 @@ class ModelImporter(private val root: INode, private val continueOnError: Boolea
154154
originalIdToExisting[expectedId] = newChild
155155
newChild
156156
} else {
157+
// The existing child node is not only moved to a new index,
158+
// it is potentially moved to a new parent and role.
157159
node.moveChild(role, index, existingNode)
160+
// If the old parent and old role synchronized before the move operation,
161+
// the existing child node would have been marked as to be deleted.
162+
// Now that it is used, it should not be deleted.
158163
nodesToRemove.remove(existingNode)
159164
existingNode
160165
}
@@ -166,6 +171,9 @@ class ModelImporter(private val root: INode, private val continueOnError: Boolea
166171
syncNode(childNode, expected, progressReporter)
167172
}
168173

174+
// At this point, all n expected children for this role are created and correctly sorted.
175+
// This means the first n children are correct.
176+
// Any child beyond that is an unexpected child has to be marked for removal.
169177
nodesToRemove += node.getChildren(role).drop(expectedNodes.size)
170178
}
171179
}

0 commit comments

Comments
 (0)