Pax.Interface.Plugin behaviour (Pax v0.0.1-dev.20251023)

View Source

Pax.Interface.Plugin is a behaviour for defining plugins that can be used with Pax.Interface.

use Pax.Interface.Plugin

When you use Pax.Interface.Plugin, your module will be declared as a behaviour for both Pax.Plugin as well as Pax.Interface.Plugin.

Summary

Types

A Phoenix.LiveView socket

Unsigned params from a Phoenix.LiveView handle_params/3

Callbacks

after_params/2 occurs after all handle_params/4 callbacks in Pax.Interface, its plugins, and the user module. It is called with the final params and socket, and must return a socket.

after_render/2 occurs after the main interface action, and before the user module gets a chance. It must always return a socket. Any changes to the socket will not trigger a re-render.

handle_async/4 occurs during the normal LV handle_async/2 callback, after the main interface action, and before the user module gets a chance. If it returns {:halt, socket} then the user module will never have its handle_async/2 called. If the plugin implements handle_async/4 at all, then it must return {:cont, socket} for any events it has no interest in handling, otherwise an UndefinedFunctionError will be raised.

handle_event/4 occurs during the normal LV handle_event/3 callback, after the main interface action, and before the user module gets a chance. If it returns {:halt, socket} then the user module will never have its handle_event/3 called. If the plugin implements handle_event/4 at all, then it must return {:cont, socket} for any events it has no interest in handling, otherwise an UndefinedFunctionError will be raised.

handle_info/3 occurs during the normal LV handle_info/2 callback, after the main interface action, and before the user module gets a chance. If it returns {:halt, socket} then the user module will never have its handle_info/2 called. If the plugin implements handle_info/3 at all, then it must return {:cont, socket} for any events it has no interest in handling, otherwise an UndefinedFunctionError will be raised.

handle_params/4 occurs during the handle_params/3 step of the LV initialization, before the main interface handles the action.

Types

socket()

@type socket() :: Phoenix.LiveView.Socket.t()

A Phoenix.LiveView socket

unsigned_params()

@type unsigned_params() :: Phoenix.LiveView.unsigned_params()

Unsigned params from a Phoenix.LiveView handle_params/3

Callbacks

after_params(opts, socket)

(optional)
@callback after_params(opts :: map(), socket :: socket()) ::
  {:cont, socket()} | {:halt, socket()}

after_params/2 occurs after all handle_params/4 callbacks in Pax.Interface, its plugins, and the user module. It is called with the final params and socket, and must return a socket.

after_render(opts, socket)

(optional)
@callback after_render(opts :: map(), socket :: socket()) :: socket()

after_render/2 occurs after the main interface action, and before the user module gets a chance. It must always return a socket. Any changes to the socket will not trigger a re-render.

handle_async(opts, name, async_fun_result, socket)

(optional)
@callback handle_async(
  opts :: map(),
  name :: term(),
  async_fun_result :: {:ok, term()} | {:exit, term()},
  socket :: socket()
) :: {:cont, socket()} | {:halt, socket()}

handle_async/4 occurs during the normal LV handle_async/2 callback, after the main interface action, and before the user module gets a chance. If it returns {:halt, socket} then the user module will never have its handle_async/2 called. If the plugin implements handle_async/4 at all, then it must return {:cont, socket} for any events it has no interest in handling, otherwise an UndefinedFunctionError will be raised.

handle_event(opts, event, params, socket)

(optional)
@callback handle_event(
  opts :: map(),
  event :: binary(),
  params :: unsigned_params(),
  socket :: socket()
) ::
  {:cont, socket()} | {:halt, socket()} | {:halt, reply :: map(), socket()}

handle_event/4 occurs during the normal LV handle_event/3 callback, after the main interface action, and before the user module gets a chance. If it returns {:halt, socket} then the user module will never have its handle_event/3 called. If the plugin implements handle_event/4 at all, then it must return {:cont, socket} for any events it has no interest in handling, otherwise an UndefinedFunctionError will be raised.

handle_info(opts, msg, socket)

(optional)
@callback handle_info(opts :: map(), msg :: term(), socket :: socket()) ::
  {:cont, socket()} | {:halt, socket()}

handle_info/3 occurs during the normal LV handle_info/2 callback, after the main interface action, and before the user module gets a chance. If it returns {:halt, socket} then the user module will never have its handle_info/2 called. If the plugin implements handle_info/3 at all, then it must return {:cont, socket} for any events it has no interest in handling, otherwise an UndefinedFunctionError will be raised.

handle_params(opts, params, uri, socket)

(optional)
@callback handle_params(
  opts :: map(),
  params :: unsigned_params(),
  uri :: String.t(),
  socket :: socket()
) ::
  {:cont, socket()} | {:halt, socket()}

handle_params/4 occurs during the handle_params/3 step of the LV initialization, before the main interface handles the action.