Guppy.Window behaviour (guppy v0.1.0)

Copy Markdown View Source

Minimal LiveView-style per-window process abstraction for Guppy.

Modules that use Guppy.Window own one native window per process. Guppy opens the window with the module's initial IR, routes native events back into the process, and rerenders automatically after window state changes.

The window struct is the primary state carrier, similar to a socket-like view state.

Required callbacks:

Optional callbacks:

Modules may also define handle_info(message, window) without marking it as a Guppy.Window callback; Guppy routes ordinary process messages there by convention.

Missing optional handlers and unmatched handler clauses are treated as no-op handlers that skip rerendering. use Guppy.Window also defines child_spec/1, so window modules can be supervised directly.

Summary

Types

callback_result()

@type callback_result() ::
  {:noreply, t()} | {:noreply, t(), :skip_render} | {:stop, term(), t()}

t()

@type t() :: %Guppy.Window{
  assigns: map(),
  private: map(),
  view_id: pos_integer() | nil
}

Callbacks

handle_event(t, map, t)

(optional)
@callback handle_event(String.t(), map(), t()) :: callback_result()

mount(term, t)

@callback mount(term(), t()) :: {:ok, t()} | {:stop, term()}

render(t)

@callback render(t()) :: term()

Functions

assign(window, attrs)

assign(window, key, value)

focus(server, timeout \\ 5000)

handle_window_message(module, message, state)

init_window(module, arg, opts \\ [])

put_private(window, key, value)

put_window_opts(window, opts)

reopen_retry_delay_ms(attempt)

Returns the reopen retry delay for a failed-reopen attempt count.

Delays double from 50ms and cap at 5000ms so a persistently failing runtime is not hammered with reopen attempts.

state(server)

update(window, key, fun)

view_id(server)