embed() doesn't unembed() previous parent
See original GitHub issueIf I’m reading the docs correctly, the entire embedding feature is designed like a tree:
cell B
might or might not have a parent. If it does, it can be cell A
.
cell A
might or might not have children. If it does, they can be [cell B, cell C, cell D...]
.
The relationship from parent to children is represented by an array on values: getEmbeds()
returns an array.
The other way around (from any given child to it’s parent) is represented as a single id: parent()
returns an id.
After playing for some days with this feature I hit a bug with how the embed()
method works: it doesn’t check (and unembed()
) whether the cell that’s going to be embedded is already embedded in another cell. This leads to an unreachable relation from the cell to it’s previous parent (and a broken tree).
Example (pseudo-code):
parent1 = cell()
parent2 = cell()
child = cell()
parent1.embed(child)
parent1.getEmbeds() <-- [child]
child.parent() <-- parent1
parent2.embed(child)
parent2.getEmbeds() <-- [child]
child.parent() <-- parent2
parent1.getEmbeds() <-- [child] // shouldn't happen. "child" belongs to "parent2" now.
Issue Analytics
- State:
- Created a year ago
- Comments:7 (7 by maintainers)
Top GitHub Comments
I was only worried about the case where we internally un-embed the cell instead of throwing error (either as default behavior or with
force
option). When we throw an error, the responsibility is on the user. Not adding theforce
option now was a conscious decision for two reasons:if (a.isEmbedded()) { a.getParentCell().unembed(a); } c.embed(a);
I am aware that none of the
batch
logic is documented (as far as I know it’s useful only with JointJS+), but you can usegraph.hasActiveBatch('fit-embeds')
.