-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCounter.purs
34 lines (28 loc) · 953 Bytes
/
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
module Examples.CounterList.Counter where
import Prelude
import Carpenter (Render, Update)
import Carpenter.Cedar (CedarClass, cedarSpec)
import React (createClass)
import React.DOM (button, div', text, h1')
import React.DOM.Props (onClick)
type Counter = Int
data CounterAction = Increment | Decrement | Remove
counterComponent :: CedarClass Counter CounterAction
counterComponent = createClass $ cedarSpec update render
update :: forall props eff. Update Counter props CounterAction eff
update yield _ action _ state =
case action of
Increment ->
yield (_ + 1)
Decrement ->
yield (_ - 1)
Remove ->
pure state
render :: forall props. Render Counter props CounterAction
render dispatch _ state _ =
div'
[ h1' [text (show state)]
, button [onClick \_ -> dispatch Increment] [text "+"]
, button [onClick \_ -> dispatch Decrement] [text "-"]
, button [onClick \_ -> dispatch Remove] [text "X"]
]