Vlad Sabev
Aug 27, 2017 · 1 min read

Hey, Maxi, thanks for the comment!

Excellent point on communicating with child components! I hadn’t considered how exactly that would work out. Here’s what I came up with:

So, you can pass functions to child components —I called the function onCountChanged instead of count to avoid conflicts with the count property which holds the component’s current count. The function is accessible via vnode.attrs.onCountChanged. Since the attributes are merged with the state, you can call onCountChanged from within increment and decrement.

Alternatively, I think you could use lifecycle events (onupdate specifically) to trigger a function every time a component’s model is updated. However, thanks to your comment, I found a shortcoming in the current HyperMithril implementation— lifecycle events don’t have access to the true state of the component — the vnode.state is an empty object that doesn’t get updated when the count changes! In some ways this is good, because you can’t accidentally mutate the state from outside the component.

Still, there should be a better way to achieve what you asked for. I’ll definitely think about that and update the post, since it’s a very common use case. Thanks again for bringing this up!

)

    Vlad Sabev

    Written by

    Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
    Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
    Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade