4 ms·
It’s done with JS but that’s all written for you. But as a bonus, LiveView apps do work without JS (they just aren’t updated over web sockets anymore).
by sodapopcan 5y ago
It’s done with JS but that’s all written for you. But as a bonus, LiveView apps do work without JS (they just aren’t updated over web sockets anymore).
- bcrosby95 5y agoI assume you have to specifically design your site to work with both the request/response model and the LiveView model in order for this to actually work, as opposed to LiveView being able to plug that hole automatically for you.
- sodapopcan 5y agoNope, all you need to do is make sure that everything has a route (which is very much encouraged in LiveView) and it works.
- sodapopcan 5y agoTo be a little more concrete, here's an example: <%= live_patch "about", to: Routes.about_path(@socket, :index) %> which creates: <a href="/about" data-phx-link="patch" data-phx-link-state="push">about</a> The data attributes are read by the LiveView HTML and are otherwise ignored by a JSless broswer. Edited to fix glaring code sample error.
- dqv 5y agoYou can design singularly for LiveView and it handles everything. But if you want both request/response and LiveView (e.g. to mix the two or fallback to r/r when no js) you have to be more explicit in your design. It’s mostly trivial though. I have authentication pages that use the old controllers but pages that use only LiveView without any hassle.