domafic-rs
domafic-rs copied to clipboard
Make it possible to map listeners to a different type
Equivalent to Elm's map. I've been working on it in the mappable-listeners branch, but it's extremely messy and requires a bunch of extra traits. A much simpler solution would be possible with ATCs on types (not just lifetimes), as then DomNode
, DomNodes
, Listener
, and Listeners
could all implement some sort of MessageFunctor
trait.
Here's an example of how one could create a mappable component without this feature:
struct ComponentMsg;
fn component_with_mappable_msg<'a, Mapper, Msg>(msg_mapper: Mapper)
-> impl DomNode<Message = Msg> + 'a
where
Msg: 'a,
Mapper: Fn(ComponentMsg) -> Msg + 'a
{
button((
on("click", move |_| msg_mapper(ComponentMsg))
))
}