akin

akin

Hey everyone,

Recently, I’ve been working on a project that uses LiveView for most of the UI, but for some parts with very complex client state, it leverages Gleam’s Lustre framework.

If you’re not familiar with it, Lustre is a Gleam frontend framework that implements the Elm architecture and takes advantage of Gleam’s ability to compile to JS for building highly interactive UIs.

I wrote a few simple helpers and components to make integration easier and improve DX. They allow Lustre to be rendered anywhere inside HEEX and communicate with LiveView from Gleam via the WebSocket connection. It’s similar to LiveSvelte or other JS integrations, but with Gleam and Lustre. It also supports server-side rendering.

Would you be interested if I release this as an open source library (lissome)? I Just want to collect feedback before start extracting the code into a library.

Showing Posts 1 to 10

lawik

lawik

Nerves Core Team

That does sound very interesting :slight_smile:

Getting to keep going with the well built-out Elixir ecosystem and proven LiveView but being able to use Gleam for shared logic between front and back seems like a neat capability.

Does this all use Plug and that server or how does Lustre get integrated?

MikaelFangel

MikaelFangel

Like the idea of this! Would love to try it out for some small hobby projects in the beginning. :blush:

akin

akin OP

Getting to keep going with the well built-out Elixir ecosystem and proven LiveView but being able to use Gleam for shared logic between front and back seems like a neat capability.

That’s exactly the motivation.

Does this all use Plug and that server or how does Lustre get integrated?

It compiles Gleam to Erlang and calls it to produce the initial html. Then compiles Gleam to JS and bundle it using esbuild binary to hydrate.This is different when using Lustre server components.

The integration is via a component, for example:

def render(assigns) do
  ~H"""
    <div>
      <div>Some content rendered with LiveView</div>
      <.lustre name="my_gleam_module" props={%{initial: 10}} />
    </div>
  """
end

The library will rely on mix_gleam, which is a tool to manage Gleam with Mix. I’ll probably change the under-hood details if I figure out a more efficient approach but now the above works well.

ignasiesbr

ignasiesbr

I would be really interested on trying this out.
I think a way to have client side state on certain parts of the application is needed for more complex UIs.
Will keep an eye on this thread :slight_smile:

akin

akin OP

Hey all! Just released the library, it’s still extremely early stage and a lot of work to do, but here is the repo and the hex package.

https://github.com/selenil/lissome/

I’ll be sharing here some new features as I add them.

13
Post #5
Papipo

Papipo

I am working on gleam support for mix. Do you want to try it out?

akin

akin OP

Sure! I’ve been running into some issues with mix_gleam, and what you’re doing will definitely help.

hayleigh

hayleigh

Wow what a cool project!

I see you’re using Lustre in its typical “SPA” mode:

pub fn main() {
  let json = get_element_by_id("ls-model")
  let flags = parse_flags(json)

  let app = lustre.simple(init, update, view)
  let assert Ok(_) = lustre.start(app, "#app", flags)

  Nil
}

and decoding flags and state like you would for traditional ssr/prerendering purposes.

You might also want to dig into Lustre’s component system: because these are built on native Web Components and you’d be able to communicate directly with a LiveView app through attributes and events like any other HTML element :slight_smile:

akin

akin OP

Thank you @hayleigh.

My plan is to eventually support all Lustre’s modes, I think that offers a lot of versatility.

akin

akin OP

Release 0.3.1

Hey, everyone! This release brings new features and a refactor to the approach taken by the library for doing the integration between Lustre and LiveView.

The highlights are:

  • All the setup and Gleam integration with Mix has been completely changed in favor of a more solid and flexible approach. Details in the README.
  • Helpers for communicating with LiveView. Now Lissome includes its own Gleam package that you can add to your Gleam project as a path dependency. It contains various helpers, among them are function to interop with Phoenix LiveView using the Lustre’s effects system.
  • A live reloader that watches for changes in your Gleam files and recompiles them.
  • Helpers to work with Gleam types and their Erlang representation in Elixir.

Next step will be support for lustre.component component and Lustre’s server components.

Where Next? Top

Trending in Discussions Top

AstonJ
As the title says, please share what you’ve been up to with Elixir. Whether that’s been learning it, looking into it, making stuff with i...
2977 94592 917
New
cblavier
Hey there, It’s been more than a year since we started using LiveView as our main UI library and building a whole library of UI componen...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
heathen
Quite interesting article Google brought me. Didn’t find any mentions about it here. What do you think in general? Would you use togethe...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
AstonJ
Since we have deprecated our Erlang sections (as we have dedicated Erlang Forums now) let’s add this thread for those who’d like to post ...
New
maennchen
:warning: Security advisory: Decimal DoS vulnerability A vulnerability has been published for decimal where very large exponents can cau...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews