PhoenixVapor.Hybrid.ServerCodegen (PhoenixVapor v0.3.0)

Copy Markdown View Source

Generates Elixir code (AST) for the server side of a hybrid component.

Produces:

  • mount/3 — initializes LiveView assigns
  • render/1 — produces %Rendered{} with server slots + props payload
  • handle_event/3 — one clause per server action

Summary

Functions

Classify each slot in the Vapor IR as server-owned or client-owned.

Generate handle_event/3 clauses for server actions.

Generate all server-side function ASTs for a hybrid component.

Functions

build_rendered(split, assigns, client_props, slot_owners, ref_defaults, computed_exprs, component_name \\ nil)

Build the %Phoenix.LiveView.Rendered{} struct at runtime.

Handles:

  • Full initial render (all slots evaluated for first paint)
  • Props JSON payload injected into the statics via a wrapper
  • Change tracking: client-owned slots still re-evaluate when their underlying server prop changes (for LV diff correctness)

classify_slots(slots, classification)

Classify each slot in the Vapor IR as server-owned or client-owned.

A slot is client-owned if any of its referenced identifiers belong to a client ref, client computed, or mixed computed.

gen_handle_events(classification)

Generate handle_event/3 clauses for server actions.

gen_render(split, classification, props, computeds \\ %{}, component_name \\ nil)

Generate the render/1 function.

The rendered output includes:

  • All slots evaluated for the initial/full render (SEO, first paint)
  • A data-pv-props attribute with JSON-encoded client-consumed props
  • Change tracking that skips client-owned slots when only client props changed

generate(split, classification, opts \\ [])

@spec generate(
  split :: map(),
  classification :: PhoenixVapor.Hybrid.Classifier.classification(),
  opts :: keyword()
) :: [Macro.t()]

Generate all server-side function ASTs for a hybrid component.

Returns a list of quoted expressions to be injected into the LiveView module.