A different way of building HTML, where attributes flow down to concrete HTML.
submitStyle = [style|
color: blue;
font-size: 36px;
|]
submitAttr =
Attribute "type" "submit"
submitButton
= submitAttr
$ submitStyle
$ button [ text "Submit" ]
Handling events follows the usual state -> event -> new state, with a little extra to send new events to itself or a parent.
data Counter =
Increment | Decrement
deriving Show
countHandler = handler' [] 0 reducer
where
reducer state Increment =
(state + 1, [])
reducer state Decrement =
(state - 1, [])
view count = div
[ h1 [ text (show count) ]
, onClick Increment $ button [ text "+" ]
, onClick Decrement $ button [ text "-" ]
]
component = countHandler view
Designed to work nicely with effects. Set an interpreter which applies to all event handlers.
interpreter' :: Eff '[Time, IOE] a -> IO a
interpreter' = runEff . runTimeIO
configuration = defaultConfiguration
{ interpreter = interpreter' }
main = serve
configuration
component