View Source Inertia.Controller (Inertia v0.4.0)
Controller functions for rendering Inertia.js responses.
Summary
Functions
Assigns a prop value to the Inertia page data.
Marks a prop value as "always included", which means it will be included in the props on initial page load and subsequent partial loads (even when it's not explicitly requested).
Marks a prop value as lazy, which means it will only get evaluated if explicitly requested in a partial reload.
Renders an Inertia response.
Types
Functions
@spec assign_prop(Plug.Conn.t(), atom(), any()) :: Plug.Conn.t()
Assigns a prop value to the Inertia page data.
Marks a prop value as "always included", which means it will be included in the props on initial page load and subsequent partial loads (even when it's not explicitly requested).
Marks a prop value as lazy, which means it will only get evaluated if explicitly requested in a partial reload.
Lazy props will only be included the when explicitly requested in a partial reload. If you want to include the prop on first visit, you'll want to use a bare anonymous function or named function reference instead.
conn
# ALWAYS included on first visit...
# OPTIONALLY included on partial reloads...
# ALWAYS evaluated...
|> assign_prop(:cheap_thing, cheap_thing())
# ALWAYS included on first visit...
# OPTIONALLY included on partial reloads...
# ONLY evaluated when needed...
|> assign_prop(:expensive_thing, fn -> calculate_thing() end)
|> assign_prop(:another_expensive_thing, &calculate_another_thing/0)
# NEVER included on first visit...
# OPTIONALLY included on partial reloads...
# ONLY evaluated when needed...
|> assign_prop(:super_expensive_thing, inertia_lazy(fn -> calculate_thing() end))
@spec render_inertia(Plug.Conn.t(), component :: String.t(), props :: map()) :: Plug.Conn.t()
Renders an Inertia response.