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

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
water
I’m aware of 2 such projects, are there others? git: GitHub - team-alembic/realworld: A fullstack Phoenix LiveView application with back...
New
itzmidinesh
Hi all, I’m working on a Phoenix project where I need to make external HTTP requests and I’m trying to choose between Req and HTTPoison....
New
peck
Hi everyone. My team and I have been working on a fairly modest app based around video streaming and chat, but we’ve landed a customer t...
New
leoschweizer
Hi, we run different LLM models across a cluster, with each node loading a configurable subset. Model-specific queues let nodes consume ...
New
csmr
Hi all, I’m new here and would like to hear peoples views on my Elixir/Phoenix based game-engine! :smiley: Mutonex gamedesign was finish...
New
Stef-Verniers
Hello I’ve been coding in Elixir for almost two years now because of my current job where we implemented Elixir in our application. But ...
New

Other Trending Topics Top

dominicletz
Hey there, I haven’t seen a list of useful Elixir specific skills for the popular AI tools yet so I’m starting one here with my first. ...
New
mudasobwa
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
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
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New
OndrejValenta
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly) AI dream has many faces, but general...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews