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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# Lustre
An Elm-inspired framework for building web apps in Gleam!
---
[](https://hex.pm/packages/lustre)
[](https://hexdocs.pm/lustre/)
```gleam
import gleam/int
import lustre
import lustre/element.{button, div, p, text}
import lustre/event.{on_click}
import lustre/cmd
pub fn main() {
let app = lustre.simple(init, update, render)
let assert Ok(_) = lustre.start(app, "#app")
Nil
}
fn init() {
0
}
type Msg {
Incr
Decr
}
fn update(state, msg) {
case msg {
Incr -> state + 1
Decr -> state - 1
}
}
fn render(state) {
div(
[],
[
button([on_click(Decr)], [text("-")]),
p([], [text(int.to_string(state))]),
button([on_click(Incr)], [text("+")]),
],
)
}
```
---
❗️ This package relies on Gleam's JavaScript FFI and is intended to be run in
the browser. **It will not work if your are targetting Node.js or Erlang.**
---
## Installation
Lustre is available on [Hex](https://hex.pm/packages/lustre). You can install
it like any other Hex package:
```sh
$ gleam add lustre
```
|