diff options
author | Hayleigh Thompson <me@hayleigh.dev> | 2023-09-23 09:11:52 +0100 |
---|---|---|
committer | Hayleigh Thompson <me@hayleigh.dev> | 2023-09-23 09:11:52 +0100 |
commit | 8da25cda86133a83854c8a4ffb47430226e9e8b1 (patch) | |
tree | 812ffb7a8b4910ed2d33e71ff3af95c597befe74 | |
parent | 1af7ef317a2fd2b1dadae8fd420b7865fe307360 (diff) | |
download | lustre-8da25cda86133a83854c8a4ffb47430226e9e8b1.tar.gz lustre-8da25cda86133a83854c8a4ffb47430226e9e8b1.zip |
:recycle: Remove conditional compilation.
Some functions are now theoretically available to the erlang target, although they will no-op. This maakes development of server-friendly and client-only components in the same codebase much nicer.
-rw-r--r-- | src/lustre.gleam | 33 | ||||
-rw-r--r-- | src/lustre/event.gleam | 5 |
2 files changed, 26 insertions, 12 deletions
diff --git a/src/lustre.gleam b/src/lustre.gleam index 7fd7ec9..1dbc770 100644 --- a/src/lustre.gleam +++ b/src/lustre.gleam @@ -10,9 +10,20 @@ import lustre/element.{Element} // TYPES ----------------------------------------------------------------------- +@target(javascript) /// 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), + ) +} + pub type Error { AppAlreadyStarted AppNotYetStarted @@ -24,7 +35,6 @@ pub type Error { // CONSTRUCTORS ---------------------------------------------------------------- -@target(javascript) /// pub fn element(element: Element(msg)) -> App(Nil, Nil, msg) { let init = fn(_) { #(Nil, effect.none()) } @@ -34,7 +44,6 @@ pub fn element(element: Element(msg)) -> App(Nil, Nil, msg) { application(init, update, view) } -@target(javascript) /// pub fn simple( init: fn(flags) -> model, @@ -47,16 +56,16 @@ pub fn simple( application(init, update, view) } -@target(javascript) /// @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), -) -> App(flags, model, msg) +) -> App(flags, model, msg) { + App(init, update, view) +} -@target(javascript) @external(javascript, "./lustre.ffi.mjs", "setup_component") pub fn component( name: String, @@ -64,23 +73,27 @@ pub fn component( update: fn(model, msg) -> #(model, Effect(msg)), view: fn(model) -> Element(msg), on_attribute_change: Map(String, Decoder(msg)), -) -> Result(Nil, Error) +) -> Result(Nil, Error) { + Ok(Nil) +} // EFFECTS --------------------------------------------------------------------- -@target(javascript) /// @external(javascript, "./lustre.ffi.mjs", "start") pub fn start( app: App(flags, model, msg), selector: String, flags: flags, -) -> Result(fn(msg) -> Nil, Error) +) -> Result(fn(msg) -> Nil, Error) { + Error(NotABrowser) +} -@target(javascript) /// @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) +} // UTILS ----------------------------------------------------------------------- diff --git a/src/lustre/event.gleam b/src/lustre/event.gleam index 8980490..8316e1a 100644 --- a/src/lustre/event.gleam +++ b/src/lustre/event.gleam @@ -15,10 +15,11 @@ type Decoded(a) = // EFFECTS --------------------------------------------------------------------- -@target(javascript) /// @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() +} // CUSTOM EVENTS --------------------------------------------------------------- |