nikhgupta

nikhgupta

Hello,

I am really really new to Elixir, and although I have tried to get started with it earlier - I, finally, started rewriting a monolith Rails app using Phoenix to fix a few things we were having troubles with (and o’course, learning new stuff helps).

So far, I am loving the components we have ported to our Elixir application, and Phoenix LiveView has been incredibly useful to speed things up. We were using Vue.js earlier, but the development workflow is so easy with LV, once we got a hang of it.

However, there is one thing we could not find any reference to. We have a huge root layout, and like in the previous Rails application we have it split across several partials. We are using LiveView on top of it, and it works beautifully. Although, the diffs are pretty huge. I figured that LiveView is sending those partials in the diff, probably because it only searches for diffs at the first level, and considers nested partials as updates to simplify diff calculation.

So, e.g. the layout is:

<%= @count %>
<%= render "partials/_nested.html", assigns %>

In the above case, LiveView diffs are returning the whole content of partials/_nested.html. If we remove the partial, and include the HTML in the code directly - the diffs go back to sane size. I guess the same warning applies here - avoid content_tag in your templates.

But, to keep the code DRY - it would be really great, if we can simply ignore such “static” partials from the diff calculation somehow? I am not sure how the diff calculation works (haven’t gone through that part of code). If possible, we would like to mark partials that do not change once rendered, and have them be ignored by LiveView in diffs. Any suggestions regarding this?

Showing Posts 1 to 8

idi527

idi527

:waving_hand:

Have you considered turning the partials into live components?

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

Is your partial a .eex or .leex file?

Dlacreme

Dlacreme

I know this is quite old but I believe this is what most of us are looking for: Phoenix.LiveComponent — Phoenix LiveView v1.2.5

david

david

For folks in the future, I thought I’d also point out that there are both Phoenix.Component and Phoenix.LiveComponent (as @Dlacreme identified). There are some “partial” use cases that might be satisfied by the former. As I’ve seen Component and LiveComponent used interchangeably in some tutorials, thought it worth mentioning.

maxie

maxie

Don’t use LiveComponents if it’s not really necessary. Use function components instead. IMHO, live component is a new process, so if you have for instance 4 liveview components you have 4 processes, it’s not elixirish!!! and also you could have a headache later passing the properties from one to other.
Also there’s no need to use function component if you don’t use them in at least one other part of the code. So it’s better to use templates like parts of the code in order not to have a spaghetti code.

The question is it possible in Elixir to render just a part of code like template
Example:

... ...
...
<%= render some template of terms_and_conditions.html.heex %>
....

this terms_and_conditions file could have some static variables (constants) for example. But in order not to have spaghetti we decouple it to a separate file

D4no0

D4no0

Not true, all live components are part of the same process.

sodapopcan

sodapopcan

To add volume to @D4no0 's comment, LiveComponents are NOT new processes and it’s important to understand that. I do agree, however, to not use a live component if you can get away with a function component. I always reach for function components first then refactor into live components once it starts to make sense to encapsulate some slice of state and behaviour within a LiveView, especially if it can be re-used elsewhere.

maxie

maxie

Ok, yes, the same process, agreed. My fault. I meant other thing: "They run inside the LiveView process but have their own state and life-cycle. For this reason, they are also often called “stateful components”. Do we always need state?! I say it because there are a lot of tutorials where every time for creating a template or a simple view a live_component is created.

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
ryanwinchester
apply_graft/2 doesn’t rewrite an add_many sub-workflow’s deps on an add step. Grafted jobs cancel with “upstream job was deleted” Version...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
marciok
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
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
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
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews