domafic-rs icon indicating copy to clipboard operation
domafic-rs copied to clipboard

Make it possible to map listeners to a different type

Open cramertj opened this issue 7 years ago • 1 comments

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.

cramertj avatar Jan 09 '17 21:01 cramertj

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))
    ))
}

cramertj avatar Jan 19 '17 00:01 cramertj