Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make it possible to map listeners to a different type #4

Open
cramertj opened this issue Jan 9, 2017 · 1 comment
Open

Make it possible to map listeners to a different type #4

cramertj opened this issue Jan 9, 2017 · 1 comment

Comments

@cramertj
Copy link
Owner

cramertj commented Jan 9, 2017

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
Copy link
Owner Author

cramertj commented Jan 19, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant