-
Notifications
You must be signed in to change notification settings - Fork 156
Closed
Description
I'm trying to store nodes in structs and use them later in view.
use case:
#[derive(Clone, Debug)]
pub enum Msg {
Home,
AboutUs
}
#[derive(Debug)]
pub struct Flexbox {
items: Vec<Node<Msg>>,
}
fn view_flexbox(flexbox: &Flexbox) -> Node<Msg> {
div![
flexbox.items.clone()
]
}
#[test]
fn test_listeners() {
let items = vec![
button![simple_ev(Ev::Click, Msg::Home), "Home"],
button![simple_ev(Ev::Click, Msg::AboutUs), "About us"]
];
let flexbox = Flexbox {items};
// this panic show that flexbox items have listeners
panic!("{:#?}", flexbox);
let node = view_flexbox(&flexbox);
// this panic show that node doesn't children doesn't have listeners
panic!("{:#?}", node);
}It seems listeners are not cloned with the node/el:
seed/src/virtual_dom/node/el.rs
Lines 206 to 221 in 60d7de4
| /// Allow the user to clone their Els. Note that there's no easy way to clone the | |
| /// closures within listeners or lifestyle hooks, so we omit them. | |
| impl<Ms> Clone for El<Ms> { | |
| fn clone(&self) -> Self { | |
| Self { | |
| tag: self.tag.clone(), | |
| attrs: self.attrs.clone(), | |
| style: self.style.clone(), | |
| children: self.children.clone(), | |
| node_ws: self.node_ws.clone(), | |
| listeners: Vec::new(), | |
| namespace: self.namespace.clone(), | |
| hooks: LifecycleHooks::new(), | |
| } | |
| } | |
| } |
Is there way to fix this ?
Metadata
Metadata
Assignees
Labels
No labels