sodapopcan

sodapopcan

In the 15 minute twitter video, Chris broadcasts the updated Post event with the entity attached which is then simply appended to the list of Posts. This is a simple operation but it does create a little bit of duplication with the domain code—a Post is added to the conceptual list of Posts in the db, then to the literal list of Posts in the LiveView state. This duplication can get a lot hairier in more complicated scenarios, though. For example, when moving an item from list to another, there are three entities involved: the item along with the source list and destination list. This would result in having to the write that logic in both the view and the domain layers.

Is this generally the route people take? Is it viable to have a view model (or data helper) pre-emptively update the state then sending the result to the db? Is there any disadvantage to that assuming you could blow up on the db update if it fails which would re-render the LiveView in the previous state?

I would love to get some feedback with different ideas on this!

Thanks!

Showing Posts 1 to 5

LostKobrakai

LostKobrakai

This is imo a fact inherently coupled to the fact that both your db and the liveview process maintain state of a list of things, which you want both to be updated. The simplest option is letting the liveview be a plain consumer and sending it the whole new list. From there it’s optimizations to improve latency, minimize data moved around and such.

sodapopcan

sodapopcan OP

Hi! Thanks for your reply!

This is what I’m currently doing but feel it’s pretty inefficient (and actually noticing a tiny bit of lag even locally when there is enough data).

I have I guess what you would call a trello-style application for posting simple post-it-note notes and it has multiple lanes. I’m currently, on every update, re-fetching every single lane with every single note when the position of a note is moved. Of course I could make it a little smarter and just update the affected lane, but then if it’s moved between lanes it gets more complex as I’d have to update two lanes.

But! As you put it, this is an inherit side-effect of separating persistence and app state and I can accept that—I just needed to hear someone else say it :smiley: I think I’m still getting used to Phoenix not being opinionated in the same way that Rails is opinionated and afraid that I’m missing out on a well-known pattern.

Thanks again!

sodapopcan

sodapopcan OP

PS, I really enjoy your blog. Your post about user-sorting opened me up to all sorts of new ideas on how to approach it.

LostKobrakai

LostKobrakai

If you need the optimization, then feel free to duplicate the business logic and make pubsub only broadcast information about what things moved. But now you’re aware why it’s there to begin with :smiley:

sodapopcan

sodapopcan OP

Oops, I replied to myself on my note about your blog… ha!

— 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
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
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
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
apz
I’m new to elixir and just tried to install the elixirLS extension for VScode(ium) and it is throwing some errors that I would like help ...
New

Other Trending Topics Top

GenericJam
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
JesseHerrick
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
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
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
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
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

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews