-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathToggler.purs
More file actions
27 lines (23 loc) · 817 Bytes
/
Toggler.purs
File metadata and controls
27 lines (23 loc) · 817 Bytes
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
module Examples.Toggler where
import Prelude
import Dispatcher (action)
import Dispatcher.React (modifyState, renderer)
import React (ReactElement, component, unsafeCreateLeafElement)
import React.DOM (button, div', h1', text)
import React.DOM.Props (onClick)
data Action = ToggleState
toggler :: ReactElement
toggler = unsafeCreateLeafElement (component "Toggler" spec) {}
where
spec this =
let eval ToggleState = modifyState (\state -> { on: not state.on })
d = action this <<< eval
render {state} =
div'
[ h1'
[ text "Toggle Button" ]
, button
[ onClick $ \_ -> d ToggleState ]
[ text (if state.on then "On" else "Off") ]
]
in pure {state: { on: false }, render: renderer render this}