DevJoy.API.Notifier behaviour (DevJoy v2.0.0)

View Source

The 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_notifier configuration key
    config :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

notify_delayed_job(func)

@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)

notify_delayed_job(func, time)

@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)

notify_fullscreen_change(boolean)

@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

notify_fullscreen_toggle()

@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

notify_index_out_of_bounds()

@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

notify_item_change(t)

@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

notify_part_change(t, name)

@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

set_notifier(module)

@spec set_notifier(module()) :: :ok

Sets a notifier implementation to be used within current process.