Open ymtszw opened 5 years ago
Actually, I think that the problem is not that the event is "evaluated twice" but that subscriptions are called after update with the new model, i.e. with model.dropdown = True
. The first branch of your if then gets called and the Dropdown False
message is immediately emitted.
See this related thread in discourse.
This doesn't change the fact that the example in the documentation is indeed confusing.
The example is as follows:
type Msg = ClickOut
subscriptions : Model -> Sub Msg subscriptions model = case model.dropDown of Closed _ -> Sub.none
When you uncomment the commented line above to provide "click out", the dropdown button itself stops working. Dropdown part is not shown at all even if you click the button.
Apparently, a click event is evaluated twice, within a single frame, before AND after model update? To prove that, I introduced "step" state before activating "click out" subscription: https://ellie-app.com/4r9djjXTZ4Fa1
This works, since it avoids suspected "double evaluation" by delaying state transition with
onAnimationFrame
.Actually, this problem had alreaday reported when it was
Mouse.clicks
in Elm 0.18. https://discourse.elm-lang.org/t/mouse-clicks-subscription-created-and-executed-following-click-event/1067 The problem continued inBrowser.Events.onClick
but I do not see the issue on the repository, so let me file it here.