manage events in Haskell

117 views Asked by At

I'm currently working with GHCJS.DOM/JSDOM in Haskell with the aim of create a small web application. In order to capture the event "click on a button" I write the following code:

releaseAction <- on element click $ do
    w <- currentWindowUnchecked
    alert w "I was clicked!"
releaseAction

(this is an example taken from the page https://hackage.haskell.org/package/jsaddle-dom-0.9.4.1/docs/JSDOM-EventM.html); the problem is the following: if I remove the last line ( so I delete releaseAction), then I can click the "element" as many times I want and consequently firing the events as many times I want. On the other hand if I don't delete the last line, this cancels the event, preventing me of firing even a single event. My goal is to let the user to click only one time the "element" and then this event must be forbidden. How I can do the job? Thanks.

1

There are 1 answers

0
Daniel Wagner On BEST ANSWER

You can use mfix:

mfix $ \releaseAction -> on element click $ do
    w <- currentWindowUnchecked
    alert w "I was clicked!"
    releaseAction