drab
drab copied to clipboard
Cohabitation with LiveView
Since LiveView is now public, probably the developers will try to use both libraries in the same app, but at this time it is not possible because Drab.Client.generate_drab_js/3
rises when it tries to get the controller module for a LV
page, as :phoenix_controller
is not present in the conn
of a LiveView page.
Checking for the presence of :live_view_module
in the conn
parameters reveals if the page is suited or not for generating the drab js, for example:
defp generate_drab_js(conn, connect?, assigns) do
if !conn.assigns[:live_view_module] do
controller = Phoenix.Controller.controller_module(conn)
...
This way both libraries can cohabit at the same time in the same app, using Drab only for pages based on Controllers/.eex templates (but not for LiveView pages because its js code will not be injected).
Edit: The PR #192 solve this problem with a more general solution than the one initially proposed above