tmjoen

tmjoen

A small QoL improvement for live components?

I was noticing when moving my app from Surface to LiveView 0.17 that it is a little harder to quickly scan the element tree when glancing at the source code when using <.live_component> mixed in with function components.

For instance:

<.fieldset heading="Project">
  <.live_component module={Input.RichText} form={@form} field={:title} id={"#{field.id}-title"} />
  <Input.slug form={@form} field={:slug} from={:title} />
  <.live_component module={Input.Image} id={"#{field.id}-image"} form={@form} field={:slug} />
  <Input.text form={@form} field={:meta_title} />
  <Input.text_area form={@form} field={:meta_description} />
  <!-- etc etc -->
<./fieldset>

I forked phoenix_live_view and added a little helper to the use Phoenix.LiveComponent logic

def live_component(assigns) do
  assigns
  |> assign(:module, __MODULE__)
  |> Phoenix.LiveView.Helpers.live_component()
end

So now my code can look like this:

<.fieldset heading="Project">
  <Input.RichText.live_component form={@form} field={:title} id={"#{field.id}-title"} />
  <Input.slug form={@form} field={:slug} from={:title} />
  <Input.Image.live_component id={"#{field.id}-image"} form={@form} field={:slug} />
  <Input.text form={@form} field={:meta_title} />
  <Input.text_area form={@form} field={:meta_description} />
  <!-- etc etc -->
<./fieldset>

Much easier to scan imo.

I have a PR ready if the Phoenix Live View team thinks this is worth having :slight_smile:

(thanks to lostkobrakai and jonr for the idea!)

Where Next?

Popular in Questions Top

rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID&lt;0.412.0&gt; terminating ** (Postgrex.Error) FATAL...
New

Other popular topics Top

KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36654 110
New
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 42533 114
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New

We're in Beta

About us Mission Statement