-
-
Save adetokunbo/825c7a9b250dbfa4e4b086cb7c3d568e to your computer and use it in GitHub Desktop.
Attaching reflex to a particular node
This file contains hidden or 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
{-# LANGUAGE ConstraintKinds #-} | |
{-# LANGUAGE FlexibleContexts #-} | |
{-# LANGUAGE RecursiveDo #-} | |
{-# LANGUAGE ScopedTypeVariables #-} | |
{-# LANGUAGE TypeFamilies #-} | |
------------------------------------------------------------------------------ | |
import Control.Concurrent | |
import Control.Monad | |
import Control.Monad.Trans | |
import Control.Monad.Trans.Reader | |
import GHCJS.DOM | |
import GHCJS.DOM.Document | |
import GHCJS.DOM.Element | |
import GHCJS.DOM.EventM (preventDefault, eventTarget) | |
import GHCJS.DOM.HTMLDocument | |
import GHCJS.DOM.Types hiding (Event, Text) | |
import Reflex.Dom hiding (getKeyEvent) | |
------------------------------------------------------------------------------ | |
------------------------------------------------------------------------------ | |
waitUntilJust :: IO (Maybe a) -> IO a | |
waitUntilJust a = do | |
mx <- a | |
case mx of | |
Just x -> return x | |
Nothing -> do | |
threadDelay 10000 | |
waitUntilJust a | |
------------------------------------------------------------------------------ | |
main :: IO () | |
main = runWebGUI $ \webView -> do | |
doc <- waitUntilJust $ liftM (fmap castToHTMLDocument) $ | |
webViewGetDomDocument webView | |
root <- waitUntilJust $ liftM (fmap castToHTMLElement) $ | |
documentGetElementById doc "app-tag-id" | |
attachWidget root webView $ do | |
yourApp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment