Skip to content

Commit

Permalink
Improve experimental API
Browse files Browse the repository at this point in the history
  • Loading branch information
ghivert committed Feb 12, 2025
1 parent dd4db75 commit 2963bbc
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
8 changes: 4 additions & 4 deletions sketch_lustre_experimental/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ import sketch/lustre/experimental as sketch_lustre
pub fn main() {
// Initialise the cache. Two strategies can be used. Ephemeral caches are designed as throw-away caches.
let assert Ok(stylesheet) = sketch.stylesheet(strategy: sketch.Ephemeral)
let assert Ok(_) = sketch.stylesheet(strategy: sketch.Ephemeral)
// Generate the partial view function, compatible with Lustre's runtime.
lustre.simple(init, update, view(_, stylesheet))
lustre.simple(init, update, view)
// And voilà!
|> lustre.start("#app", Nil)
}
fn view(model, stylesheet) {
fn view(model) {
// Add the sketch CSS generation "view middleware".
use <- sketch_lustre.render(stylesheet, [sketch_lustre.node()])
use <- sketch_lustre.render(in: [sketch_lustre.node()])
// Run your actual view function.
my_view(model)
}
Expand Down
2 changes: 1 addition & 1 deletion sketch_lustre_experimental/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
"clean": "gleam clean"
},
"devDependencies": {
"@chouqueth/gleam": "^1.6.3"
"@chouqueth/gleam": "^1.8.1"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ pub fn setup(stylesheet: sketch.StyleSheet) -> Result(sketch.StyleSheet, Nil) {
/// }
/// ```
pub fn render(
stylesheet stylesheet: sketch.StyleSheet,
in outputs: List(Container),
after view: fn() -> el.Element(msg),
) -> el.Element(msg) {
let new_view = view()
let assert Ok(stylesheet) = global.get_stylesheet()
let content = sketch.render(stylesheet)
use view, stylesheet <- list.fold(outputs, new_view)
case stylesheet {
Expand Down Expand Up @@ -117,11 +117,9 @@ pub fn render(
/// html.div([], [])
/// }
/// ```
pub fn ssr(
stylesheet: sketch.StyleSheet,
view: fn() -> el.Element(a),
) -> el.Element(a) {
pub fn ssr(view: fn() -> el.Element(a)) -> el.Element(a) {
let new_view = view()
let assert Ok(stylesheet) = global.get_stylesheet()
let content = sketch.render(stylesheet)
case contains_head(new_view) {
True -> put_in_head(new_view, content)
Expand Down

0 comments on commit 2963bbc

Please sign in to comment.