-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCounter.purs
37 lines (31 loc) · 1 KB
/
Counter.purs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
module Examples.Counter.Counter where
import Prelude
import Carpenter (spec, Render, Update)
import Control.Monad.Eff.Class (liftEff)
import Control.Monad.Eff.Console (log, CONSOLE)
import React (createClass, ReactClass)
import React.DOM (text, button, h1', div')
import React.DOM.Props (onClick)
type State = Int
data Action = Init | Increment | Decrement
counterClass :: ReactClass _
counterClass = createClass $ spec 0 update render
update :: forall props eff. Update State props Action (console :: CONSOLE | eff)
update yield _ action _ _ =
case action of
Init -> do
liftEff $ log "Initializing"
yield (const 0)
Increment -> do
liftEff $ log "Incrementing"
yield (_ + 1)
Decrement -> do
liftEff $ log "Decrementing"
yield (_ - 1)
render :: forall props. Render State props Action
render dispatch _ state _ =
div'
[ h1' [text (show state)]
, button [onClick \_ -> dispatch Increment] [text "+"]
, button [onClick \_ -> dispatch Decrement] [text "-"]
]