Last active
June 4, 2020 00:12
-
-
Save Ebmtranceboy/18b2e2eeae2d47b56050753c201aa6cc to your computer and use it in GitHub Desktop.
Concur counter
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 Effect.Class (liftEffect) | |
import Effect.Console (log) | |
import Concur.Core (Widget) | |
import Concur.React (HTML) | |
import Concur.React.DOM (div_, h2_, hr', text, div', p', button) as D | |
import Concur.React.Props as P | |
import Concur.React.Run (runWidgetInDom) | |
import Control.Alt ((<|>)) | |
import Control.MultiAlternative (orr) | |
counterWidget :: forall a. Int -> Widget HTML a | |
counterWidget count = do | |
n <- D.div' | |
[ D.p' [D.text ("State: " <> show count)] | |
, D.button [P.onClick] [D.text "Increment"] $> count+1 | |
, D.button [P.onClick] [D.text "Decrement"] $> count-1 | |
] | |
liftEffect (log ("COUNT IS NOW: " <> show n)) | |
counterWidget n | |
main :: Effect Unit | |
main = do | |
runWidgetInDom "main" $ orr | |
[ widget (counterWidget 0 <|> counterWidget 100) "Counter" | |
] | |
where | |
widget w s = orr | |
[ D.hr' | |
, D.h2_ [] $ D.text s | |
, D.div_ [] w | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment