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.<p>My apologies for the terrible elixir syntax highlighting in this post. I keep putting off finding a good way to do this on Blogger.
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.<p>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.<p>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).
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?