Are Msgs batched by default

After seeing this thread I wondered if batched Msgs might explain a situation I had recently. Essentially a button opens a menu of other buttons. The menu is a child element of the main button. Thus clicking any menu button sends the Msg associated with its own onClick event as well as that of the main button’s onClick Msg. This results in the menu being kept open even after the view updates. I still can’t decide if that’s intentional or a bug.

Event propagation is a feature of JavaScript (DOM), and not specific to Elm. Here’s one short article about it: A simplified explanation of event propagation in JavaScript

Actually the proper solution to your earlier problem probably would’ve been to use stopPropagationOn so that standard event propagation is stopped.

That has a bit trickier syntax than normal events. Instead of e.g.

Events.onClick YourMessage

you need to use:

Events.stopPropagationOn "click" (JD.succeed (YourMessage, True))

Here’s a small example:
If you click on first “INNER” text, you get both Inner and Outer messages, but if you click on second “INNER” text you get only Inner message as propagation is stopped.

1 Like

Excellent explanation, thanks. I should probably have mentioned I was building the app with mdgriffith/elm-ui, which does not at this time have stopPropagationOn. I’m not actually sure if I could use Element.html to work this in or not.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.