DaAnalyst
Maybe I’m asking too much and maybe this is a language issue, not a LiveView one but still, can it be made for function components to be defdelegated to from another module and work as good when used from that other module?
By work as good I mean those slot's and attr's reporting compile time errors when something that’s required is not specified.
Ex:
defmodule SpecificComponents do
use Phoenix.Component
attr :id, :string, required: true
attr :name, :string, required: true
attr :role, :string, default: nil
def account( assign)
embed_templates "specific_components/*" # containing `account.html.heex`
end
defmodule OverallComponents do
defdelegate account( assigns), to: SpecificComponents
end
defmodule Example do
...
import OverallCompoenents
def render( assigns) do
~H"""
<div>
<.account id="account" />
</div>
"""
end
end
This compiles (on latest Phoenix, LiveView, Elixir) without complaining the otherwise required name attribute is missing.
Trending in Proposals: Ideas
Other Trending Topics
Edit: 2026 May 15 - This post is archived.
Mob is alive!!
Main docs: mob v0.7.11 — Documentation
A bit of explanation for the slightly c...
New
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
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
A little off-topic, but I feel like people here have a good head on their shoulders.
I used to be quite good at making software. Was luc...
New
Latest Phoenix Threads
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ai
- #ecto-query
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #metaprogramming
- #hex










Showing Posts 1 to 3- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
LostKobrakai
defdelegateis just a macro replace typing out the followingNothing here creates’s attrs or slots for
OverallComponents.account/1. I’m not sure if the live view compiler could make use of the doc metadata.Personally I’d argue that this seems like useless complexity. Why not use the
SpecificComponentsone directly. No indirection and no need to search around where the actual code is. The docs the LSP shows will be correct and so on.DaAnalyst
As to why not use them directly..
It’s because they all used to be defined in the
OverallComponents(e.g.CoreComponents) where most of them still reside and the app templates depends on those. But then we started replacing Alpine with custom elements, so I thought it would be nice to colocate together the LiveView heex templates of individual components and/or component groups and the related web component heex files into their subfolders.While at it (and that’s where it went wrong), I thought it’d also be nice to move their definitions into the respective small subfolder context
.exfiles because I took it for granted thatdefdelegatewould sort it out automatically. Obviously I didn’t take a peek at howdefdelegateactually works.Seems like I’m gonna be moving those definitions back into the “overall” modules leaving just the template files grouped. Not a big deal, but it would be truly nice if there was a way to achieve this intent.
sodapopcan
Well this explains a lot… d’oh me. cc: @dviramontes
But ya, I used a very similar pattern at my last job, mostly so all components could be mass imported.