diff options
author | Hayleigh Thompson <me@hayleigh.dev> | 2023-07-19 11:46:37 +0100 |
---|---|---|
committer | Hayleigh Thompson <me@hayleigh.dev> | 2023-07-19 11:46:37 +0100 |
commit | 410b190a13d6e0d5059f1ea719c60a41e69d9825 (patch) | |
tree | d9427bcc13ac9bce22d43202ae37d58589db67f6 | |
parent | d70ba66fafb485c9d4541a503ff55f96c5c5255e (diff) | |
download | lustre-410b190a13d6e0d5059f1ea719c60a41e69d9825.tar.gz lustre-410b190a13d6e0d5059f1ea719c60a41e69d9825.zip |
:recycle: Create the proper error type in javascript and save the pointless ffi wrapper.
-rw-r--r-- | src/lustre.ffi.mjs | 3 | ||||
-rw-r--r-- | src/lustre.gleam | 17 |
2 files changed, 6 insertions, 14 deletions
diff --git a/src/lustre.ffi.mjs b/src/lustre.ffi.mjs index b57026f..59fe49b 100644 --- a/src/lustre.ffi.mjs +++ b/src/lustre.ffi.mjs @@ -1,5 +1,6 @@ import { morph } from "./runtime.ffi.mjs"; import { Ok, Error } from "./gleam.mjs"; +import { ElementNotFound } from "./lustre.mjs"; import { map } from "./lustre/element.mjs"; // RUNTIME --------------------------------------------------------------------- @@ -40,7 +41,7 @@ export class App { return new Ok((msg) => this.dispatch(msg)); } catch (_) { - return new Error(undefined); + return new Error(new ElementNotFound()); } } diff --git a/src/lustre.gleam b/src/lustre.gleam index 5c36750..bbeb39b 100644 --- a/src/lustre.gleam +++ b/src/lustre.gleam @@ -2,7 +2,6 @@ // IMPORTS --------------------------------------------------------------------- -import gleam/result import lustre/effect.{Effect} import lustre/element.{Element} @@ -200,10 +199,10 @@ pub fn simple( /// = "" "window.setTimeout" ///``` @external(javascript, "./lustre.ffi.mjs", "setup") -pub fn application(init init: fn() -> #(model, Effect(msg)), update update: Update( +pub fn application(init: fn() -> #(model, Effect(msg)), update: Update( model, msg, - ), render render: Render(model, msg)) -> App(model, msg) + ), render: Render(model, msg)) -> App(model, msg) // EFFECTS --------------------------------------------------------------------- @@ -231,16 +230,8 @@ pub fn application(init init: fn() -> #(model, Effect(msg)), update update: Upda /// function from your `main` (or elsewhere) you can get events into your Lustre /// app from the outside world. /// -pub fn start( - app: App(model, msg), - selector: String, -) -> Result(fn(msg) -> Nil, Error) { - start_(app, selector) - |> result.replace_error(ElementNotFound) -} - @external(javascript, "./lustre.ffi.mjs", "start") -fn start_(app app: App(model, msg), selector selector: String) -> Result( +pub fn start(app: App(model, msg), selector: String) -> Result( fn(msg) -> Nil, - Nil, + Error, ) |