stefan-hoeck / idris2-dom-mvc

Single Page Web Applications in Idris
BSD 3-Clause "New" or "Revised" License
18 stars 2 forks source link

Event callbacks changed with `attr` accumulate #29

Open gergoerdi opened 1 year ago

gergoerdi commented 1 year ago

[I don't have a standalone reproducer, but I think it's straightforward enough]

I have a view that looks like this:

public export
display : St -> Cmd Ev
display s = batch
  [ attr playBtn $ onClick $ Play (not s.playing)
  , child playBtn $ span [ classes ["bi", if s.playing then "bi-pause-fill" else "bi-play-fill"] ] []
  ]

So this changes the onClick event of the playBtn every time the UI is updated. However, it seems that attr playBtn $ onClick e doesn't replace playBtn's onClick callback; rather, it extends it so now clicking the button yields two events. Then after the next update, it will yield three events and so on. And gods help you if this display ends up running in response to that Play event...

Note that the documentation explicitly mentions attr as valid for changing callbacks:

  • attr: Sets a single attribute at a node. This could also be a new event.
stefan-hoeck commented 1 year ago

Yes, this is indeed currently not possible. For the time being it would be best do update the documentation, because I currently don't see an easy way for enabling this.