from Hacker News

Phoenix LiveView: Async Assign Pattern

by gnutrino on 6/14/23, 6:37 PM with 22 comments

  • by gnutrino on 6/14/23, 6:37 PM

    I started using this pattern in my LiveView projects, and finally rolled it into a common module for others to use. I've found it really helps clean up the mount function, which can get pretty messy as your LiveViews grow over time.

    My apologies for the terrible elixir syntax highlighting in this post. I keep putting off finding a good way to do this on Blogger.

  • by vinnymac on 6/14/23, 7:54 PM

    I haven't written Elixir professionally the last couple of years, but I was an early user of LiveView when it was first demoed at a conference.

    As someone who currently writes applications using React Server Components, I am interested to see how concepts like LiveView evolve over time. We are now shipping significantly more HTML than before, and a lot less Javascript, as more has been moved to the server.

    Makes me wish LiveView was portable to every other platform I work on, rather than having to convince companies to write more Elixir (although that isn't a bad thing).

  • by ramchip on 6/15/23, 12:01 AM

    Does this work well with tests? For instance, if you click a button in a test, do you need to do something special to ensure the async update has happened before checking assertions on the HTML contents?
  • by tommica on 6/14/23, 8:11 PM

    Looks really useful and neat especially the way it chains so fluently for parallerization
  • by wahnfrieden on 6/14/23, 8:27 PM

    Anyone doing similar with Swift given it also has server continuations?