Let's say I need to create an event listener with ghcjs-dom that triggers on a click and then removes itself.
I have
addListener :: (IsEventTarget t, IsEvent e)
=> t -> EventName t e -> SaferEventListener t e -> Bool -> IO ()
removeListener :: (IsEventTarget t, IsEvent e)
=> t -> EventName t e -> SaferEventListener t e -> Bool -> IO ()
for adding and removing, and
newListener :: (IsEvent e) => EventM t e () -> IO (SaferEventListener t e)
to create the listener using an EventM
. How can I get access to the SaferEventListener
(which will be constructed later) from within the EventM
, so I can remove it when the event occurs?
In JavaScript, you typically use a named function expression as your callback for addEventListener
, and then apply removeEventListener
to that name inside the callback function. However, it seems there is no direct equivalent here. Am I missing something?