DevJoy.API.Notifier behaviour (DevJoy v2.0.0)
View SourceThe Notfier API defines a set of notification callbacks to implement
as well as functions that call a callback implementation for the configured notifier module.
The default notifier module that implements this module's behaviour is DevJoy.Session.Notifier.
Usage
The notifier can be configured:
- globally using the
:session_notifierconfiguration keyconfig :dev_joy, :session_notifier, MyApp.Notifier - per process using set_notifier/1 function
DevJoy.API.Storage.set_storage(MyApp.Storage)
Summary
Callbacks
A special synchronous variant of notify_delayed_job/2.
This is only useful when we do not expect any delays.
Sends an asynchronous notification with the specified anonymous function. The function is to be called after the specified amount of time has elapsed.
Sends a notification when the full screen mode has changed.
Sends a notification when the full screen mode is toggled.
Sends a notification when there are no subsequent elements after the current element in the current scene part.
Sends a notification when current item is changed.
Sends a notification when current part is changed.
Functions
Sets a notifier implementation to be used within current process.
Callbacks
@callback notify_delayed_job(func :: (-> any())) :: :ok
A special synchronous variant of notify_delayed_job/2.
This is only useful when we do not expect any delays.
Usage
The notification will be sent within all asynchronous Session functions.
The notification is handled by the handler
generated by use DevJoy.API.Notifier.
:ok = DevJoy.API.Notifier.notify_delayed_job(fn -> :done end)@callback notify_delayed_job(func :: (-> any()), time :: non_neg_integer()) :: :ok
Sends an asynchronous notification with the specified anonymous function. The function is to be called after the specified amount of time has elapsed.
Usage
The notification will be sent within all asynchronous Session functions.
The notification is handled by the handler
generated by use DevJoy.API.Notifier.
:ok = DevJoy.API.Notifier.notify_delayed_job(200, fn -> :done end)@callback notify_fullscreen_change(boolean()) :: :ok
Sends a notification when the full screen mode has changed.
Usage
The notification will be sent within the handler generated by
Session.LiveView.
def handle_info({:dev_joy, :fullscreen_changed, fullscreen}, socket) do
{:noreply, assign(socket, fullscreen: fullscreen)}
end@callback notify_fullscreen_toggle() :: :ok
Sends a notification when the full screen mode is toggled.
Usage
The notification is handled by the handler
generated by Session.LiveView.
def handle_event("btn-fullscreen-click", _params, socket) do
:ok = DevJoy.API.Notifier.notify_fullscreen_toggle()
{:noreply, socket}
end@callback notify_index_out_of_bounds() :: :ok
Sends a notification when there are no subsequent elements after the current element in the current scene part.
Usage
The notification will be sent within the Session.next/1.
def handle_info({:dev_joy, :index_out_of_bounds}, socket) do
DevJoy.Session.get({MyApp.MainScene, :main, 1})
{:noreply, socket}
end@callback notify_item_change(DevJoy.API.Item.t()) :: :ok
Sends a notification when current item is changed.
Usage
The notification will be sent within various Session functions.
def handle_info({:dev_joy, :item_changed, item}, socket) do
{:noreply, assign(socket, item: item)}
end@callback notify_part_change(DevJoy.Scene.t(), DevJoy.Scene.Part.name()) :: :ok
Sends a notification when current part is changed.
Usage
The notification will be sent within various Session functions.
The notification is handled by the handler
generated by Session.LiveView.
:ok = DevJoy.API.Notifier.notify_part_change(MyApp.MainScene, :main)Functions
@spec set_notifier(module()) :: :ok
Sets a notifier implementation to be used within current process.