diff options
author | Hayleigh Thompson <me@hayleigh.dev> | 2023-07-19 22:03:41 +0100 |
---|---|---|
committer | Hayleigh Thompson <me@hayleigh.dev> | 2023-07-19 22:03:41 +0100 |
commit | be928f231f8fbf716593cde1a80387b8539d4635 (patch) | |
tree | 3df6a79456a6c2e96e9043f578eb858681bdaa35 /src/lustre.gleam | |
parent | 2950d216902d3b4b21e8421ae390f63d1ea8ea7b (diff) | |
download | lustre-be928f231f8fbf716593cde1a80387b8539d4635.tar.gz lustre-be928f231f8fbf716593cde1a80387b8539d4635.zip |
:sparkles: Add support for nested lustre apps as custom web components.
Diffstat (limited to 'src/lustre.gleam')
-rw-r--r-- | src/lustre.gleam | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/lustre.gleam b/src/lustre.gleam index bbeb39b..4998a50 100644 --- a/src/lustre.gleam +++ b/src/lustre.gleam @@ -2,6 +2,8 @@ // IMPORTS --------------------------------------------------------------------- +import gleam/dynamic.{Decoder} +import gleam/map.{Map} import lustre/effect.{Effect} import lustre/element.{Element} @@ -49,6 +51,7 @@ pub type App(model, msg) pub type Error { ElementNotFound + ComponentAlreadyRegistered } // These types aren't exposed, but they're just here to try and shrink the type @@ -204,6 +207,15 @@ pub fn application(init: fn() -> #(model, Effect(msg)), update: Update( msg, ), render: Render(model, msg)) -> App(model, msg) +@external(javascript, "./lustre.ffi.mjs", "setup_component") +pub fn component(name: String, init: fn() -> #(model, Effect(msg)), update: Update( + model, + msg, + ), render: Render(model, msg), on_attribute_change: Map(String, Decoder(msg))) -> Result( + Nil, + Error, +) + // EFFECTS --------------------------------------------------------------------- /// Once you have created a app with either `basic` or `application`, you |