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 
(thanks to lostkobrakai and jonr for the idea!)
Popular in Questions
In Ruby, I can go:
User.find_by(email: "foobar@email.com").update(email: "hello@email.com")
How can I do something similar in Elixir? ...
New
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
What is the idiomatic way of matching for not nil in Elixir?
E.g.,
First way:
defp halt_if_not_signed_in(conn, signed_in_account) when...
New
i’m a new one to elixir
which editor can i use
vs code? or atom?
Thanks! :smiley:
New
Hey guys.
I'm new to elixir and im really stocked about it. But I ran into a bit of problem - I need to convert a date sting, for examp...
New
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this
"1000"
What is the ...
New
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible.
total = 10
while total != 0
...
New
Given a string, how can I get access to its character by index? Enum.at("my_string", 2) doesn't work.
Or rather, not char, but a substr...
New
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum.
...
New
Hi,
I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
Other popular topics
Hello!
tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability.
After spen...
New
In Ruby, I can go:
User.find_by(email: "foobar@email.com").update(email: "hello@email.com")
How can I do something similar in Elixir? ...
New
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this:
...
New
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service.
Currently when I de...
New
How to set Jason to encode all fields in ecto schema, I don’t care about security and implementing only is taking long list of attributes...
New
I would like to know what is the best IDE for elixir development?
New
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
New
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
New
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
New
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including.
What is Phoenix LiveV...
New







