100phlecs
Are there any downsides, like perf issues, to putting all functional components in CoreComponents as long as you prefix it with the context for organization, i.e. blog_navbar, app_navbar ?
Previously I’ve sectioned them out by context into their own modules, but I think this may not have many benefits as I often prefix the function with its context.
What’s your approach?
Trending in Discussions
As the title says, please share what you’ve been up to with Elixir. Whether that’s been learning it, looking into it, making stuff with i...
New
Hey there,
It’s been more than a year since we started using LiveView as our main UI library and building a whole library of UI componen...
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
Quite interesting article Google brought me. Didn’t find any mentions about it here.
What do you think in general? Would you use togethe...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
Since we have deprecated our Erlang sections (as we have dedicated Erlang Forums now) let’s add this thread for those who’d like to post ...
New
What IDE or editor are you using for Elixir development?
Personally, I use Zed, and I really like it, but sometimes I wish there were a ...
New
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
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself.
My main conc...
New
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
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #hex
- #security










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
fceruti
I don’t like the
CoreComponentsmodule approach. To me it feels like that messy drawer in your house where you keep that extra battery, plastic sunglasses and all sort of random things.What I like to do, is create more topical modules such as
Layout,InputorModal. Then you can alias them where you’d importCoreComponentsand then call from anywhere<Layout.sidebar />,<Input.select />,<Modal.toast />etc etc.Maybe at first the benefits aren’t that great, but consider these case:
<Layout.sidebar />v/s<.sidebar_layout />How do you know where
sidebar_layoutis coming from? You’d need to check for an implementation in the current module, inside any of the imports, inside yourusecall or any of it’s imports. That can get really tricky as the project grows.Layout.sidebarstays O(1) for definition retrieval.Another complexity
CoreComponentintroduces is the question to the developer: Should this component be a CoreComponent? That is not always easy to answer and ultimately meaningless. It’s the worst kind of decision to make.sodapopcan
I break them up by type under a
Componentsnamespace and just import everything everywhere.While one of my favourite things about Elixir is the locality—I very, very rarely
aliasand onlyimportif there is one per module so it’s obvious where it’s coming from—this isn’t important to me at all when it comes to components because it’s dead obvious that<.foo />is a component so I know where to look/grep. The additional module provides no further context, I just grep inlive/my_app_web/components/. You also learn very quickly what you own and what comes from Phoenix.I move stuff from
CoreComponentsintoMyAppWeb.Components.Form,MyAppWeb.Components.Modal, etc and create others. Then myComponentsmodule looks like:Then
use MyAppWeb.Componentsinlive_view/0inlib/my_app_web.exand bam, all my components are available everywhere.The drawback here is that you can’t
use MyAppWeb, :componentin your components as you’ll obviously get circular dependencies and it won’t compile. If I do need to reference other components in my components, I just use the fully qualified version, but of course you can also alias or whatever.100phlecs
So are there actually perf improvements by using
Module.componentor by definition retrieval you meant navigating the codebase?In either case I understand the appeal, especially for large Phoenix projects.
What I’m proposing in the OP would be a nightmare on a team with more than a couple devs.
Interesting way to go about it, thanks!
100phlecs
Sectioning them out but still importing them all seems interesting. I think the main appeal to one large
CoreComponentsis an ability to reference every single component in another one: can that be achieved here? I.e. you can use all theLinkscomponents in components defined within theFormorModalsodapopcan
Yes but you have to full qualify them. The big drawback ehere is that it’s easier to introduce cyclical references. This can be avoided if you sort of think about your components in “layers” (there’s a correlation to Tailwind’s layers there) or actually they could be metaprogrammed into one big module. Or they could just be one big module, of course. I’ve learned to accept larger modules since getting comfortable with FP but the way I navigate codebases is still suited to smaller files—for example, if I’m working on a new file with no component calls yet and I want to use a form component, my first instinct is to fuzzy search for
comp/formthen scroll through the file to see what I got, so that’s why I break them up like that. I could always improve my editor tooling, of course.cjbottaro
CoreComponentsis 100% my junk drawer and I’m ok with it…That’s not to say we don’t have
ClientComponents,AcaComponents,WhateverFeatureComponents…But I don’t think having a junk drawer is bad until it overflows and then you start organizing.
amym114
I’ve been trying to figure this out too and have come up with the following guidelines for my own projects. Anyone see anything I’m not thinking of here?
components/core_components.ex- These are imported into
view_helpersin the whatever_web.ex file so are accessible through any view, live component, or component by default- Aside: My main concern with customizing
core_components.exis having there be a major update that it’s then tedious to update the styles per component. I also think for this reason that this file should only have the functions it ships with within it./components/directory and imported intoview_helpers/components/too, but if they’re specific to certain views, they should only be imported as neededaiwaiwa
My 2 cents (feeling adventures)
flash_components.ex:form_components.ex:modal_components.ex:show_components.ex:error_components.ex:And certainly
project_web.exwill have to rewire:cmo
There are a couple of tools that will show you the diff between versions.
This file is full of examples to be modified by the user. We don’t want another bootstrap situation where all the liveview sites look the same do we
?
greven
Tis is how I do it too.