Skip to content

Instantly share code, notes, and snippets.

@mightybyte
Last active March 20, 2018 05:50
Show Gist options
  • Save mightybyte/a81ff034ae6ca2a4d45d to your computer and use it in GitHub Desktop.
Save mightybyte/a81ff034ae6ca2a4d45d 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
@AphonicChaos
Copy link

Get the following traceback

Main.hs:40:23:
    Couldn't match type ‘DOMWindow’
                   with ‘Widget
                           Reflex.Spider.Internal.Spider
                           (Gui
                              Reflex.Spider.Internal.Spider
                              Reflex.Spider.Internal.SpiderHost
                              (Reflex.Host.Class.HostFrame Reflex.Spider.Internal.Spider))
                           ()’
    Expected type: Widget
                     Reflex.Spider.Internal.Spider
                     (Gui
                        Reflex.Spider.Internal.Spider
                        Reflex.Spider.Internal.SpiderHost
                        (Reflex.Host.Class.HostFrame Reflex.Spider.Internal.Spider))
                     ()
      Actual type: WebView
    In the second argument of ‘attachWidget’, namely ‘webView’
    In a stmt of a 'do' block: attachWidget root webView

Not exactly sure what to put after the do block. I tried "el "div" $ text "Welcome to Reflex"", which yielded similar complaints about webView.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment