Skip to content

Instantly share code, notes, and snippets.

@adetokunbo
Forked from mightybyte/Main.hs
Created March 20, 2018 05:50
Show Gist options
  • Save adetokunbo/825c7a9b250dbfa4e4b086cb7c3d568e to your computer and use it in GitHub Desktop.
Save adetokunbo/825c7a9b250dbfa4e4b086cb7c3d568e to your computer and use it in GitHub Desktop.
Attaching reflex to a particular node
{-# 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