55 lines
1 KiB
Gleam
55 lines
1 KiB
Gleam
|
import gleam/int
|
||
|
import lustre
|
||
|
import lustre/attribute
|
||
|
import lustre/element.{type Element}
|
||
|
import lustre/element/html
|
||
|
import lustre/event
|
||
|
|
||
|
pub fn main() {
|
||
|
let app = lustre.simple(init, update, view)
|
||
|
let assert Ok(dispatch) = lustre.start(app, "#app", Nil)
|
||
|
|
||
|
dispatch
|
||
|
}
|
||
|
|
||
|
type Model =
|
||
|
Int
|
||
|
|
||
|
fn init(_) -> Model {
|
||
|
0
|
||
|
}
|
||
|
|
||
|
pub type Msg {
|
||
|
Increment
|
||
|
Decrement
|
||
|
}
|
||
|
|
||
|
fn update(model: Model, msg: Msg) -> Model {
|
||
|
case msg {
|
||
|
Increment -> model + 1
|
||
|
Decrement -> model - 1
|
||
|
}
|
||
|
}
|
||
|
|
||
|
fn view(model: Model) -> Element(Msg) {
|
||
|
let count = int.to_string(model)
|
||
|
|
||
|
html.div(
|
||
|
[],
|
||
|
[
|
||
|
html.h1([], [element.text("Gleam + Vite + Tauri")]),
|
||
|
html.p(
|
||
|
[attribute.style([#("text-align", "center")])],
|
||
|
[element.text("Gleam counter " <> count <> " ✨")],
|
||
|
),
|
||
|
html.p(
|
||
|
[attribute.style([#("text-align", "center")])],
|
||
|
[
|
||
|
html.button([event.on_click(Decrement)], [element.text("-")]),
|
||
|
html.button([event.on_click(Increment)], [element.text("+")]),
|
||
|
],
|
||
|
),
|
||
|
],
|
||
|
)
|
||
|
}
|