aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lustre.gleam45
-rw-r--r--src/lustre/event.gleam6
2 files changed, 30 insertions, 21 deletions
diff --git a/src/lustre.gleam b/src/lustre.gleam
index 1dbc770..fd79fa4 100644
--- a/src/lustre.gleam
+++ b/src/lustre.gleam
@@ -17,11 +17,7 @@ pub type App(flags, model, msg)
@target(erlang)
///
pub opaque type App(flags, model, msg) {
- App(
- init: fn(flags) -> #(model, Effect(msg)),
- update: fn(model, msg) -> #(model, Effect(msg)),
- view: fn(model) -> Element(msg),
- )
+ App
}
pub type Error {
@@ -59,20 +55,33 @@ pub fn simple(
///
@external(javascript, "./lustre.ffi.mjs", "setup")
pub fn application(
- init: fn(flags) -> #(model, Effect(msg)),
- update: fn(model, msg) -> #(model, Effect(msg)),
- view: fn(model) -> Element(msg),
+ _init: fn(flags) -> #(model, Effect(msg)),
+ _update: fn(model, msg) -> #(model, Effect(msg)),
+ _view: fn(model) -> Element(msg),
) -> App(flags, model, msg) {
- App(init, update, view)
+ // Applications are not usable on the erlang target. For those users, `App`
+ // is an opaque type (aka they can't see its structure) and functions like
+ // `start` and `destroy` are no-ops.
+ //
+ // Because the constructor is marked as `@target(erlang)` for some reason we
+ // can't simply refer to it here even though the compiler should know that the
+ // body of this function can only be entered from erlang (because we have an
+ // external def for javascript) but alas, it does not.
+ //
+ // So instead, we must do this awful hack and cast a `Nil` to the `App` type
+ // to make everything happy. Theoeretically this is not going to be a problem
+ // unless someone starts poking around with their own ffi and at that point
+ // they deserve it.
+ dynamic.unsafe_coerce(dynamic.from(Nil))
}
@external(javascript, "./lustre.ffi.mjs", "setup_component")
pub fn component(
- name: String,
- init: fn() -> #(model, Effect(msg)),
- update: fn(model, msg) -> #(model, Effect(msg)),
- view: fn(model) -> Element(msg),
- on_attribute_change: Map(String, Decoder(msg)),
+ _name: String,
+ _init: fn() -> #(model, Effect(msg)),
+ _update: fn(model, msg) -> #(model, Effect(msg)),
+ _view: fn(model) -> Element(msg),
+ _on_attribute_change: Map(String, Decoder(msg)),
) -> Result(Nil, Error) {
Ok(Nil)
}
@@ -82,16 +91,16 @@ pub fn component(
///
@external(javascript, "./lustre.ffi.mjs", "start")
pub fn start(
- app: App(flags, model, msg),
- selector: String,
- flags: flags,
+ _app: App(flags, model, msg),
+ _selector: String,
+ _flags: flags,
) -> Result(fn(msg) -> Nil, Error) {
Error(NotABrowser)
}
///
@external(javascript, "./lustre.ffi.mjs", "destroy")
-pub fn destroy(app: App(flags, model, msg)) -> Result(Nil, Error) {
+pub fn destroy(_app: App(flags, model, msg)) -> Result(Nil, Error) {
Ok(Nil)
}
diff --git a/src/lustre/event.gleam b/src/lustre/event.gleam
index 8316e1a..897fbdf 100644
--- a/src/lustre/event.gleam
+++ b/src/lustre/event.gleam
@@ -17,7 +17,7 @@ type Decoded(a) =
///
@external(javascript, "../lustre.ffi.mjs", "emit")
-pub fn emit(event: String, data: any) -> Effect(msg) {
+pub fn emit(_event: String, _data: any) -> Effect(msg) {
effect.none()
}
@@ -171,11 +171,11 @@ pub fn mouse_position(event: Dynamic) -> Decoded(#(Float, Float)) {
// UTILS -----------------------------------------------------------------------
@external(javascript, "../lustre.ffi.mjs", "prevent_default")
-pub fn prevent_default(event: Dynamic) -> Nil {
+pub fn prevent_default(_event: Dynamic) -> Nil {
Nil
}
@external(javascript, "../lustre.ffi.mjs", "stop_propagation")
-pub fn stop_propagation(event: Dynamic) -> Nil {
+pub fn stop_propagation(_event: Dynamic) -> Nil {
Nil
}