Skip to content

Commit

Permalink
Minor: added docs & test-case for updated 'Taffy::remove()' behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
inobelar committed Jul 17, 2023
1 parent c9e45e5 commit c08d6a2
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/tree/taffy_tree/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ impl Taffy {
}
}

// Remove "parent" references to a node when removing that node
if let Some(children) = self.children.get(key) {
for child in children.iter().copied() {
self.parents[child.into()] = None;
Expand Down Expand Up @@ -666,6 +667,22 @@ mod tests {
assert_eq!(taffy.child_count(node).unwrap(), 0);
}

// Related to: https://github.com/DioxusLabs/taffy/issues/510
#[test]
fn remove_child_updates_parents() {
let mut taffy = Taffy::new();

let parent = taffy.new_leaf(Style::default()).unwrap();
let child = taffy.new_leaf(Style::default()).unwrap();

taffy.add_child(parent, child).unwrap();

taffy.remove(parent).unwrap();

// Once the parent is removed this shouldn't panic.
assert!(taffy.set_children(child, &[]).is_ok());
}

#[test]
fn replace_child_at_index() {
let mut taffy = Taffy::new();
Expand Down

0 comments on commit c08d6a2

Please sign in to comment.