forked from purescript-react/purescript-react-basic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathActions.purs
37 lines (28 loc) · 879 Bytes
/
Actions.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 Actions where
import Prelude
import Effect.Console (log)
import React.Basic (Component, JSX, StateUpdate(..), createComponent, make, runUpdate)
import React.Basic.DOM as R
import React.Basic.DOM.Events (capture_)
component :: Component Props
component = createComponent "Counter"
type Props =
{ label :: String
}
data Action
= Increment
actions :: Props -> JSX
actions = make component { initialState, render }
where
initialState = { counter: 0 }
update self = case _ of
Increment ->
UpdateAndSideEffects
(self.state { counter = self.state.counter + 1 })
\{ state } -> log $ "Count: " <> show state.counter
send = runUpdate update
render self =
R.button
{ onClick: capture_ $ send self Increment
, children: [ R.text (self.props.label <> ": " <> show self.state.counter) ]
}