Skip to content

Instantly share code, notes, and snippets.

@Ebmtranceboy
Created June 5, 2020 11:38
Show Gist options
  • Save Ebmtranceboy/ae664b12758cd25a5732591dd74a7b87 to your computer and use it in GitHub Desktop.
Save Ebmtranceboy/ae664b12758cd25a5732591dd74a7b87 to your computer and use it in GitHub Desktop.
Composable Hello Concur
module Main where
import Prelude
import Effect (Effect)
import Concur.Core (Widget)
import Concur.React (HTML)
import Concur.React.DOM (text, div', button) as D
import Concur.React.Props as P
import Concur.React.Run (runWidgetInDom)
getGreeting :: Widget HTML String
getGreeting = D.div'
[ "Hello" <$ D.button [P.onClick] [D.text "Say Hello"]
, "Namaste" <$ D.button [P.onClick] [D.text "Say Namaste"]
]
showGreeting :: String -> Widget HTML Unit
showGreeting greeting = D.div'
[ D.text (greeting <> " Sailor!")
, void $ D.button [P.onClick] [D.text "restart"]
]
hello1 :: forall a. Widget HTML a
hello1 = do
greeting <- getGreeting
showGreeting greeting
hello1
hello2 :: String -> forall a. Widget HTML a
hello2 prev = hello2 =<< D.div'
[ D.text ("Previous greeting - " <> prev)
, do
greeting <- getGreeting
showGreeting greeting
pure greeting
]
helloWithPrev :: forall a. Widget HTML a
helloWithPrev = hello2 ""
main :: Effect Unit
main = do
runWidgetInDom "main" $ hello2 ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment