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
|
import gleam/int
import lustre
import lustre/attribute.{ style }
import lustre/element.{ button, div, p, text }
import lustre/event.{ dispatch, on_click }
pub fn main () {
let selector = "[data-lustre-container]"
let program = lustre.application(0, update, render)
lustre.start(program, selector)
}
type Action {
Incr
Decr
}
fn update (state, action) {
case action {
Incr ->
state + 1
Decr ->
state - 1
}
}
fn render (state) {
div([ style([ #("display", "flex") ]) ], [
button([ on_click(dispatch(Decr)) ], [ text("-") ]),
p([], [ int.to_string(state) |> text ]),
button([ on_click(dispatch(Incr)) ], [ text("+") ])
])
}
|