DevJoy.Session.LiveView (DevJoy v2.0.0)
View SourceGenerates a handlers used for communication with JavaScript API
and LiveView's page_title assign.
Usage
Generates a handler for
notify_fullscreen_toggle/0 and
notify_part_change/2 notifications sent by
Session.Notifier.
defmodule MyApp.PageLive do
use DevJoy.Session.LiveView
endFull Screen
The generated handlers supports the dev_joy:fullscreenchange socket message
and sends dev_joy:fullscreen-toggle message.
This allows a developer to toggle the fullscreen mode by just calling a single function.
def handle_event("fullscreen-btn-click", _params, socket) do
DevJoy.Session.toggle_fullscreen()
{:noreply, socket}
endHowever in some cases you may still want to track the fullscreen state by yourself
in order to for example to support 2 icons (enter and exit fullscreen).
Since the handler uses
notify_fullscreen_change/1
this becomes as simple as assigning a fullscreen value:
def handle_info({:dev_joy, :fullscreen_changed, fullscreen}, socket) do
{:noreply, assign(socket, fullscreen: fullscreen)}
endLiveView integration
The newly generated LiveView application supports page_title assign.
However in the normal case you have to change the title every time you navigate.
Since every part optionally supports passing page_title,
various Session functions sends a
notify_part_change/2 notification
and the generated handler supports this notification, the developer does not need to update
the page_title assign every time the part changes.
Additionally when you navigate to a part with page_title
set to nil the notification would not be sent, so for example setting
a page_title only on the :main part while defining multiple parts
will actually set the scene's page title.
defmodule MyApp.Scene do
use DevJoy.Scene
part :main, page_title: "Scene title" do
# …
end
part :second_part do
# …
end
part :third_part do
# …
end
end
defmodule MyApp.PageLive do
use DevJoy.Session.LiveView
def mount(_unsigned_params, _session, socket) do
DevJoy.Session.get({MyApp.Scene, :main, 1})
{:ok, socket}
end
end