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
Hello, how can I check the Phoenix version ?
Thanks !
New
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
Lets say I have map like this fetching from my database
%{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
lets say i have a sample like
a = 20; b = 10;
if (a > b) do
{:ok, "a"}
end
if (a < b) do
{:ok, b}
end
if (a == b) do
{:ok, "equa...
New
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
Hey,
Just curious what are the main benefits of Elixir compared to Clojure?
When is Elixir more useful than Clojure and vice versa?
Th...
New
Hello everyone,
I try to use an Javascript Event Handler in my root.html.leex file.
Therefore I created a function in the app.js file: ...
New
Other popular topics
I have an umbrella app.
Some of the apps inside depend on other apps in the umbrella, unsurprisingly.
I’m writing a test for one of the...
New
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
New
Phoenix 1.4.0 released
Phoenix 1.4 is out! This release ships with exciting new features, most notably
with HTTP2 support, improved deve...
New
What learn first? Rust or Elixir
Hi Elixir community!
I’m here because i want learn a new language. I’m a junior developer and mainly i ...
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
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #hex
- #security









