aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHayleigh Thompson <me@hayleigh.dev>2022-05-14 06:23:27 +0100
committerHayleigh Thompson <me@hayleigh.dev>2022-05-14 06:23:27 +0100
commit4f7a0a88c8110d4f0bb0d89683f87f2f99f1629e (patch)
treea59f4bf5df0c8214d63ebc8a68686df586ba829b
parent101bf051131105a8fd8e714d7d6dc910a6eb5ef9 (diff)
downloadlustre-4f7a0a88c8110d4f0bb0d89683f87f2f99f1629e.tar.gz
lustre-4f7a0a88c8110d4f0bb0d89683f87f2f99f1629e.zip
:memo: Write some doc comments.
-rw-r--r--src/lustre.gleam33
1 files changed, 27 insertions, 6 deletions
diff --git a/src/lustre.gleam b/src/lustre.gleam
index 0f119b1..da0730b 100644
--- a/src/lustre.gleam
+++ b/src/lustre.gleam
@@ -14,26 +14,47 @@ pub opaque type Program(state, action) {
Program(
init: state,
update: Update(state, action),
- render: View(state, action)
+ render: Render(state, action)
)
}
-///
-pub type Element(action) = element.Element(action)
-///
+pub type Element(action) = element.Element(action)
pub type Attribute(action) = attribute.Attribute(action)
-///
+// These types aren't exposed, but they're just here to try and shrink the type
+// annotations for `Program` and `program` a little bit. When generating docs,
+// Gleam automatically expands type aliases so this is purely for the benefit of
+// those reading the source.
+//
type Update(state, action) = fn (state, action) -> state
type Render(state, action) = fn (state) -> Element(action)
// CONSTRUCTORS ----------------------------------------------------------------
+/// Create a basic lustre program that just renders some element on the page.
+/// Note that this doesn't mean the content is static! With `element.stateful`
+/// you can still create components with local state.
+///
+/// Basic lustre programs don't have any *global* application state and so the
+/// plumbing is a lot simpler. If you find yourself passing state
+///
+pub fn basic (element: Element(any)) -> Program(Nil, any) {
+ let init = Nil
+ let update = fn (_, _) { Nil }
+ let render = fn (_) { element }
+
+ Program(init, update, render)
+}
+
+/// Create a more complex application mimicing TEA – the Elm architecture. We
+/// start with some initial `state`, a function to update that state, and then
+/// a render function to derive our program's view from that state.
///
-pub fn program (init: state, update: Update(state, action), render: Render(state, action)) -> Program(state, action) {
+///
+pub fn application (init: state, update: Update(state, action), render: Render(state, action)) -> Program(state, action) {
Program(init, update, render)
}