Breeze.Runtime.Hook behaviour (Breeze v0.5.0)

Copy Markdown View Source

Opt-in lifecycle hook for tooling built around a Breeze runtime.

Hooks are configured per server with :runtime_hooks:

runtime_hooks: [
  {MyMetricsHook, []},
  {MyDevelopmentTool, sample_every: 5},
  {MyAnimationHook, notify_animation?: true}
]

Periodic animation passes are quiet by default and require notify_animation?: true.

Hooks run synchronously after a committed lifecycle event. The supplied Breeze.Runtime.Context lazily exposes runtime state and diagnostics, so a hook pays for only the data it chooses to read. Slow storage or processing should be handed off to another process.

Summary

Types

config()

@type config() :: module() | {module(), keyword()}

event()

@type event() :: :rendered

hook_state()

@type hook_state() :: term()

t()

@type t() :: %Breeze.Runtime.Hook{
  module: module(),
  notify_animation?: boolean(),
  state: hook_state()
}

Callbacks

handle_event(event, t, hook_state)

@callback handle_event(event(), Breeze.Runtime.Context.t(), hook_state()) ::
  {:noreply, hook_state()}

init(keyword, map)

(optional)
@callback init(
  keyword(),
  map()
) :: {:ok, hook_state()} | hook_state()