aboutsummaryrefslogtreecommitdiff
path: root/src/lustre.gleam
diff options
context:
space:
mode:
authorHayleigh Thompson <me@hayleigh.dev>2022-03-21 20:03:23 +0000
committerHayleigh Thompson <me@hayleigh.dev>2022-03-21 20:03:23 +0000
commit101bf051131105a8fd8e714d7d6dc910a6eb5ef9 (patch)
treeca302e933ba89d090045542814c9b84259b15f74 /src/lustre.gleam
parent170a249f1bc5caae55ae5a3469f0fc6beef63568 (diff)
downloadlustre-101bf051131105a8fd8e714d7d6dc910a6eb5ef9.tar.gz
lustre-101bf051131105a8fd8e714d7d6dc910a6eb5ef9.zip
:sparkles: Add support for components with encapsulated state.
Diffstat (limited to 'src/lustre.gleam')
-rw-r--r--src/lustre.gleam19
1 files changed, 9 insertions, 10 deletions
diff --git a/src/lustre.gleam b/src/lustre.gleam
index 2058da6..0f119b1 100644
--- a/src/lustre.gleam
+++ b/src/lustre.gleam
@@ -2,17 +2,19 @@
// IMPORTS ---------------------------------------------------------------------
+
import lustre/element
import lustre/attribute
// TYPES -----------------------------------------------------------------------
+
///
pub opaque type Program(state, action) {
Program(
init: state,
update: Update(state, action),
- view: View(state, action)
+ render: View(state, action)
)
}
@@ -25,22 +27,19 @@ pub type Attribute(action) = attribute.Attribute(action)
///
type Update(state, action) = fn (state, action) -> state
-type View(state, action) = fn (state) -> Element(action)
+type Render(state, action) = fn (state) -> Element(action)
// CONSTRUCTORS ----------------------------------------------------------------
+
///
-pub fn create (init: state, update: Update(state, action), view: View(state, action)) -> Program(state, action) {
- Program(init, update, view)
+pub fn program (init: state, update: Update(state, action), render: Render(state, action)) -> Program(state, action) {
+ Program(init, update, render)
}
+// EFFECTS ---------------------------------------------------------------------
+
///
pub external fn start (program: Program(state, action), selector: String) -> Nil
= "./lustre/ffi.mjs" "mount"
-
-
-// CONVERSIONS -----------------------------------------------------------------
-///
-pub external fn to_element (program: Program(state, action)) -> Element(a)
- = "./lustre/ffi.mjs" "Program"