diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/client-runtime.ffi.mjs | 2 | ||||
-rw-r--r-- | src/lustre.gleam | 23 |
2 files changed, 12 insertions, 13 deletions
diff --git a/src/client-runtime.ffi.mjs b/src/client-runtime.ffi.mjs index 13e3906..0b6c58f 100644 --- a/src/client-runtime.ffi.mjs +++ b/src/client-runtime.ffi.mjs @@ -19,7 +19,7 @@ export class LustreClientApplication { selector instanceof HTMLElement ? selector : document.querySelector(selector); - if (!root) return new Error(new ElementNotFound()); + if (!root) return new Error(new ElementNotFound(selector)); const app = new LustreClientApplication(init(flags), update, view, root); return new Ok((msg) => app.send(msg)); diff --git a/src/lustre.gleam b/src/lustre.gleam index 74742e1..77c86cf 100644 --- a/src/lustre.gleam +++ b/src/lustre.gleam @@ -155,9 +155,9 @@ pub type Action(runtime, msg) = /// pub type Error { ActorError(StartError) - BadComponentName - ComponentAlreadyRegistered - ElementNotFound + BadComponentName(name: String) + ComponentAlreadyRegistered(name: String) + ElementNotFound(selector: String) NotABrowser NotErlang } @@ -232,11 +232,10 @@ pub fn start( } @external(javascript, "./client-runtime.ffi.mjs", "start") -fn do_start( - _app: App(flags, model, msg), - _selector: String, - _flags: flags, -) -> Result(fn(Action(ClientSpa, msg)) -> Nil, Error) { +fn do_start(_app: App(flags, model, msg), _selector: String, _flags: flags) -> Result( + fn(Action(ClientSpa, msg)) -> Nil, + Error, +) { // It should never be possible for the body of this function to execute on the // Erlang target because the `is_browser` guard will prevent it. Instead of // a panic, we still return a well-typed `Error` here in the case where someone @@ -247,10 +246,10 @@ fn do_start( /// /// @external(javascript, "./server-runtime.ffi.mjs", "start") -pub fn start_server_component( - app: App(flags, model, msg), - with flags: flags, -) -> Result(fn(Action(ServerComponent, msg)) -> Nil, Error) { +pub fn start_server_component(app: App(flags, model, msg), with flags: flags) -> Result( + fn(Action(ServerComponent, msg)) -> Nil, + Error, +) { use runtime <- result.map(start_actor(app, flags)) actor.send(runtime, _) } |