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
|
||||
|
|
|
@ -1,60 +1,68 @@
|
|||
import aurinko/updater/pubsub
|
||||
import aurinko/updater/registry
|
||||
import gleam/erlang/process
|
||||
import gleam/int
|
||||
import gleam/io
|
||||
import glubsub
|
||||
import lustre
|
||||
import lustre/attribute
|
||||
import lustre/effect
|
||||
import lustre/element.{type Element}
|
||||
import lustre/element/html
|
||||
import lustre/event
|
||||
import lustre/server_component
|
||||
import lustre/ui
|
||||
|
||||
pub type Params {
|
||||
Params(
|
||||
updater_pubsub: pubsub.UpdaterPubSub,
|
||||
updater_registry: registry.UpdaterRegistry,
|
||||
)
|
||||
}
|
||||
|
||||
// MAIN ------------------------------------------------------------------------
|
||||
|
||||
pub fn app(_updater_pubsub, _updater_registry) {
|
||||
lustre.simple(init, update, view)
|
||||
pub fn app() {
|
||||
lustre.application(init, update, view)
|
||||
}
|
||||
|
||||
// MODEL -----------------------------------------------------------------------
|
||||
|
||||
type Model =
|
||||
Int
|
||||
|
||||
fn init(initial_count: Int) -> Model {
|
||||
case initial_count < 0 {
|
||||
True -> 0
|
||||
False -> initial_count
|
||||
pub opaque type Model {
|
||||
Model(
|
||||
updater_pubsub: pubsub.UpdaterPubSub,
|
||||
updater_registry: registry.UpdaterRegistry,
|
||||
)
|
||||
}
|
||||
|
||||
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 ----------------------------------------------------------------------
|
||||
|
||||
pub opaque type Msg {
|
||||
Incr
|
||||
Decr
|
||||
UpdaterPubSub(pubsub.OutMessage)
|
||||
}
|
||||
|
||||
fn update(model: Model, msg: Msg) -> Model {
|
||||
case msg {
|
||||
Incr -> model + 1
|
||||
Decr -> model - 1
|
||||
}
|
||||
fn update(model: Model, msg: Msg) {
|
||||
io.debug("MSG UPDATE")
|
||||
io.debug(msg)
|
||||
#(model, effect.none())
|
||||
}
|
||||
|
||||
// VIEW ------------------------------------------------------------------------
|
||||
|
||||
fn view(model: Model) -> Element(Msg) {
|
||||
let styles = [#("width", "100vw"), #("height", "100vh"), #("padding", "1rem")]
|
||||
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 view(model: Model) {
|
||||
ui.stack([], [])
|
||||
}
|
||||
// fn send_initial_dataset(
|
||||
// conn: mist.WebsocketConnection,
|
||||
|
|
|
@ -10,6 +10,12 @@ pub fn view() {
|
|||
attribute.rel("stylesheet"),
|
||||
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.body([], [
|
||||
|
|
|
@ -22,8 +22,9 @@ pub fn on_init(
|
|||
updater_registry: registry.UpdaterRegistry,
|
||||
) {
|
||||
let self = process.new_subject()
|
||||
let app = main.app(updater_pubsub, updater_registry)
|
||||
let assert Ok(main_subject) = lustre.start_actor(app, 0)
|
||||
let app = main.app()
|
||||
let assert Ok(main_subject) =
|
||||
lustre.start_actor(app, main.Params(updater_pubsub, updater_registry))
|
||||
|
||||
process.send(
|
||||
main_subject,
|
||||
|
|
Loading…
Reference in a new issue