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
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
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
There are three potential reasons for members of this forum to have a look at https://vutuv.de
You are tired or annoyed of LinkedIn.
Yo...
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
- #blog-post
- #phoenix_html
- #iex
- #graphql
- #ai
- #genstage
- #elixirconf-us
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex










First 3 of 3 Posts
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.