Skip to content

Commit

Permalink
feat: add View::on support for CoreComponent::{DynChild, Each} (#2422)
Browse files Browse the repository at this point in the history
  • Loading branch information
zakstucke authored Apr 1, 2024
1 parent b79037b commit 9f1c09e
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions leptos_dom/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -771,9 +771,26 @@ impl View {
});
}
Self::CoreComponent(c) => match c {
CoreComponent::DynChild(_) => {}
CoreComponent::Each(_) => {}
_ => {}
CoreComponent::DynChild(d) => {
if let Some(subview) = *d.child.take() {
let subview = subview.on(event, event_handler);
d.child.replace(Box::new(Some(subview)));
}
}
CoreComponent::Each(each) => {
let event_handler = Rc::new(RefCell::new(event_handler));
let new_children = each.children.take().into_iter().map(|item| {
if let Some(mut item) = item {
let event_handler = Rc::clone(&event_handler);
item.child = item.child.on(event.clone(), Box::new(move |e| event_handler.borrow_mut()(e)));
Some(item)
} else {
None
}
}).collect::<Vec<_>>();
each.children.replace(new_children);
}
CoreComponent::Unit(_) => {}
},
_ => {}
}
Expand Down

0 comments on commit 9f1c09e

Please sign in to comment.