Created
November 1, 2022 17:34
-
-
Save dfithian/05156955ccdb70a6738f94f9875fd4f0 to your computer and use it in GitHub Desktop.
Haskell Reflex Window Unload Event
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Control.Lens ((^.)) | |
import Language.Javascript.JSaddle (JSCallAsFunction, MonadJSM, js2, jsg, liftJSM) | |
import Reflex.Dom (Event, MonadWidget, newTriggerEvent) | |
onWindowUnload :: MonadWidget t m => m (Event t ()) | |
onWindowUnload = do | |
(event, trigger) <- newTriggerEvent | |
let body :: JSCallAsFunction = \_ _ [_event] -> liftIO (trigger ()) | |
void . liftJSM $ jsg "window" ^. js2 "addEventListener" "beforeunload" body | |
pure event |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment