Created
June 5, 2020 11:38
-
-
Save Ebmtranceboy/ae664b12758cd25a5732591dd74a7b87 to your computer and use it in GitHub Desktop.
Composable Hello Concur
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
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