Some observations about Chris McCord's new LiveView demo project todo_trek

June 08, 2023

I always find myself reading the Phoenix LiveView changelog with baited breath. Chris McCord, the author of Phoenix, has done a stellar job steering the ecosystem. Whenever the Phoenix team releases new features, I'm on the lookout for opportunities to learn and improve my mastery of Elixir and Phoenix. As of Phoenix LiveView 0.19, Chris also released a reference codebase to help demo the new features for nested streams and form changeset apis.

Here's a short list of some learnings that I've identified while perusing the todo_trek code.

Using structs to annotate Phoenix Component attribute types

Throughout documentation I've seen usages of :map but hadn't seen the specific type specified. I don't doubt that this appeared in more recent boilerplate generated by mix phx.new.

  #...
  # Here JS is being used to denote the type vs using a "plain" :map
  attr :on_cancel, JS, default: %JS{}

  def modal(assigns) do
  #...

Passing streams down

Another pattern that I thought was interesting was the way that streams are passed down as the source of truth throughout the code for the todo list.

Event pattern

This pattern isn't necessarily new. McCord's live_beats app also used this pattern, but seeing it a second time

References


© 2024, Built with ❤️ by Blake Dietz