From 170a249f1bc5caae55ae5a3469f0fc6beef63568 Mon Sep 17 00:00:00 2001 From: Hayleigh Thompson Date: Sun, 20 Mar 2022 10:58:23 +0000 Subject: :construction: Morphdom is dead, long live React. --- src/lustre.gleam | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/lustre.gleam (limited to 'src/lustre.gleam') diff --git a/src/lustre.gleam b/src/lustre.gleam new file mode 100644 index 0000000..2058da6 --- /dev/null +++ b/src/lustre.gleam @@ -0,0 +1,46 @@ +//// + + +// 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) + ) +} + + +/// +pub type Element(action) = element.Element(action) +/// +pub type Attribute(action) = attribute.Attribute(action) + + +/// +type Update(state, action) = fn (state, action) -> state +type View(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 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" -- cgit v1.2.3