jc00ke

jc00ke

LiveView naming and dir structure

I’m wondering what the best practices are around naming and organizing LiveViews and their components. How do you go about naming them, and how do you organize your directory structure?

I’m currently doing this (and I’m not in love with it, but maybe it’s OK)

» tree lib/widget_web/views/live/
lib/widget_web/views/live/
├── shared
│   └── x_live.ex ------------ # WidgetWeb.Shared.XLive
├── foo_live.ex -------------- # WidgetWeb.FooLiveView
└── table
    ├── components
    │   └── row_component.ex - # WidgetWeb.TableLiveView.RowComponent
    └── table_live.ex -------- # WidgetWeb.TableLiveView

I forgot where I found the following projectionist snippet, but it’s by default generating module names like WidgetWeb.Views.Live.FooView which also kinda seems OK but a little too tied to the dir structure.

.projections.json

{
  "lib/**/views/*_view.ex": {
    "type": "view",
    "alternate": "test/{dirname}/views/{basename}_view_test.exs",
    "template": [
      "defmodule {dirname|camelcase|capitalize}.{basename|camelcase|capitalize}View do",
      "  use {dirname|camelcase|capitalize}, :view",
      "end"
    ]
  }
}

I’d love to hear your thoughts, thanks!

First Post!

chouzar

chouzar

I’m personally a fan of keeping most of my files in a single directory. As of now I like to create a “components” directory for views which are meant to be embedded.

Having said that, I have only used liveview for toy projects so I wouldn’t know if in a big project my directory structure would follow a “generic component” based approach or maybe a “context aware approach”.

Where Next?

Popular in Questions Top

joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
aalberti333
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
alice
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
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New

Other popular topics Top

jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New
AngeloChecked
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
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New

We're in Beta

About us Mission Statement