Crashing version
This commit is contained in:
parent
c08f162db2
commit
6ac6e4bd7f
4 changed files with 49 additions and 34 deletions
|
@ -1,2 +1,2 @@
|
||||||
gleam 1.2.1
|
gleam 1.3.0
|
||||||
erlang 27.0
|
erlang 27.0
|
||||||
|
|
|
@ -1,60 +1,68 @@
|
||||||
|
import aurinko/updater/pubsub
|
||||||
|
import aurinko/updater/registry
|
||||||
|
import gleam/erlang/process
|
||||||
import gleam/int
|
import gleam/int
|
||||||
|
import gleam/io
|
||||||
|
import glubsub
|
||||||
import lustre
|
import lustre
|
||||||
import lustre/attribute
|
import lustre/attribute
|
||||||
|
import lustre/effect
|
||||||
import lustre/element.{type Element}
|
import lustre/element.{type Element}
|
||||||
import lustre/element/html
|
import lustre/element/html
|
||||||
import lustre/event
|
import lustre/event
|
||||||
|
import lustre/server_component
|
||||||
import lustre/ui
|
import lustre/ui
|
||||||
|
|
||||||
|
pub type Params {
|
||||||
|
Params(
|
||||||
|
updater_pubsub: pubsub.UpdaterPubSub,
|
||||||
|
updater_registry: registry.UpdaterRegistry,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
// MAIN ------------------------------------------------------------------------
|
// MAIN ------------------------------------------------------------------------
|
||||||
|
|
||||||
pub fn app(_updater_pubsub, _updater_registry) {
|
pub fn app() {
|
||||||
lustre.simple(init, update, view)
|
lustre.application(init, update, view)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MODEL -----------------------------------------------------------------------
|
// MODEL -----------------------------------------------------------------------
|
||||||
|
|
||||||
type Model =
|
pub opaque type Model {
|
||||||
Int
|
Model(
|
||||||
|
updater_pubsub: pubsub.UpdaterPubSub,
|
||||||
fn init(initial_count: Int) -> Model {
|
updater_registry: registry.UpdaterRegistry,
|
||||||
case initial_count < 0 {
|
)
|
||||||
True -> 0
|
|
||||||
False -> initial_count
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn init(params: Params) {
|
||||||
|
let self = process.new_subject()
|
||||||
|
let assert Ok(_) = glubsub.subscribe(params.updater_pubsub, self)
|
||||||
|
|
||||||
|
let selector =
|
||||||
|
process.new_selector()
|
||||||
|
|> process.selecting(self, fn(m) { lustre.dispatch(UpdaterPubSub(m)) })
|
||||||
|
let selector_effect = server_component.set_selector(selector)
|
||||||
|
|
||||||
|
#(Model(params.updater_pubsub, params.updater_registry), selector_effect)
|
||||||
}
|
}
|
||||||
|
|
||||||
// UPDATE ----------------------------------------------------------------------
|
// UPDATE ----------------------------------------------------------------------
|
||||||
|
|
||||||
pub opaque type Msg {
|
pub opaque type Msg {
|
||||||
Incr
|
UpdaterPubSub(pubsub.OutMessage)
|
||||||
Decr
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update(model: Model, msg: Msg) -> Model {
|
fn update(model: Model, msg: Msg) {
|
||||||
case msg {
|
io.debug("MSG UPDATE")
|
||||||
Incr -> model + 1
|
io.debug(msg)
|
||||||
Decr -> model - 1
|
#(model, effect.none())
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// VIEW ------------------------------------------------------------------------
|
// VIEW ------------------------------------------------------------------------
|
||||||
|
|
||||||
fn view(model: Model) -> Element(Msg) {
|
fn view(model: Model) {
|
||||||
let styles = [#("width", "100vw"), #("height", "100vh"), #("padding", "1rem")]
|
ui.stack([], [])
|
||||||
let count = int.to_string(model)
|
|
||||||
|
|
||||||
ui.centre(
|
|
||||||
[attribute.style(styles)],
|
|
||||||
ui.stack([], [
|
|
||||||
ui.button([event.on_click(Incr)], [element.text("+")]),
|
|
||||||
html.slot([]),
|
|
||||||
html.p([attribute.style([#("text-align", "center")])], [
|
|
||||||
element.text(count),
|
|
||||||
]),
|
|
||||||
ui.button([event.on_click(Decr)], [element.text("-")]),
|
|
||||||
]),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
// fn send_initial_dataset(
|
// fn send_initial_dataset(
|
||||||
// conn: mist.WebsocketConnection,
|
// conn: mist.WebsocketConnection,
|
||||||
|
|
|
@ -10,6 +10,12 @@ pub fn view() {
|
||||||
attribute.rel("stylesheet"),
|
attribute.rel("stylesheet"),
|
||||||
attribute.href("./static/lustre-ui.css"),
|
attribute.href("./static/lustre-ui.css"),
|
||||||
]),
|
]),
|
||||||
|
html.link([
|
||||||
|
attribute.rel("icon"),
|
||||||
|
attribute.href(
|
||||||
|
"data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%2210 0 100 100%22><text y=%22.90em%22 font-size=%2290%22>🌅</text></svg>",
|
||||||
|
),
|
||||||
|
]),
|
||||||
html.title([], "Aurinko"),
|
html.title([], "Aurinko"),
|
||||||
]),
|
]),
|
||||||
html.body([], [
|
html.body([], [
|
||||||
|
|
|
@ -22,8 +22,9 @@ pub fn on_init(
|
||||||
updater_registry: registry.UpdaterRegistry,
|
updater_registry: registry.UpdaterRegistry,
|
||||||
) {
|
) {
|
||||||
let self = process.new_subject()
|
let self = process.new_subject()
|
||||||
let app = main.app(updater_pubsub, updater_registry)
|
let app = main.app()
|
||||||
let assert Ok(main_subject) = lustre.start_actor(app, 0)
|
let assert Ok(main_subject) =
|
||||||
|
lustre.start_actor(app, main.Params(updater_pubsub, updater_registry))
|
||||||
|
|
||||||
process.send(
|
process.send(
|
||||||
main_subject,
|
main_subject,
|
||||||
|
|
Loading…
Reference in a new issue