Skip to content

Instantly share code, notes, and snippets.

@metruzanca
Last active September 7, 2024 23:06
Show Gist options
  • Save metruzanca/27b8f587428f7ff31c8f404105a2ed81 to your computer and use it in GitHub Desktop.
Save metruzanca/27b8f587428f7ff31c8f404105a2ed81 to your computer and use it in GitHub Desktop.
Can't help but wonder if Lustre could have less noise. Without adding a preprocessor, maybe we can use a pipeline instead?

Current

  html.div([], [
    html.button([event.on_click(Increment)], [
      element.text("+")
    ]),
    element.text(count),
    html.button([event.on_click(Decrement)], [
      element.text("-")
    ]),
  ])

Function chaining (typescript/similar)

html
  .div()
  .children(
    html
      .button()
      .on_click(Increment)
      .text("+"),

    html
      .button()
      .on_click(Decrement)
      .text("-"),
  )

Equivalent of function chaining for Gleam

html.div()
|> attr.children([
   html.button()
   |> attr.on_click(Increment)
   |> attr.text("-"),

   html.button()
   |> attr.on_click(Increment)
   |> attr.text("+"),
])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment