Hi, I was wondering if it was possible in Yew to render components with generic type parameters.
I am imagining something like:
#[derive(Properties, Clone, Debug)]
pub struct TreeData<P: Properties> {
pub element: P,
pub expanded: bool,
pub children: Vec<TreeData<P>>
}
pub struct TreeView<C: Component> {
props: TreeData<<C as Component>::Properties>,
link: ComponentLink<Self>,
}
impl<C: Component> Component for TreeView<C> {
type Message = Msg;
type Properties = TreeData<<C as Component>::Properties>;
...
fn view(&self) -> Html {
html!{
<div class="tree-node" style="margin-left: 20px" >
<C // generic component
{self.props.element} // create with generic properties
/>
</div>
{
if self.props.expanded {
html!{
<div>{
for self.props.children.iter().cloned().enumerate().map(|(i,child)| html!{
<TreeView<C> // also generic
element={child.element}
children={child.children}
expanded={child.expanded}
message_parent={Some(self.child_messenger(i))}
/>
})
}</div>
}
} else {
html!{}
}
}
</div>
}
}
...
}
Would something like this already possible or would this need to be implemented first?