IslandView
IslandView — template helpers for embedding islands in server-rendered HTML.
Use these functions in controller templates to render island wrappers and include the client runtime scripts.
Dataflow modes: island_server/2 — Server-mode island (read-only, no event listeners) island/2 — Client-mode island (owns its state, handles events) island_ssr/3 — Client-mode with server-rendered inner HTML
Channel sync (Client mode only): island_with_channel/3 — wire up a channel topic; state syncs after each update
Parent-child binding: island_child/4 — child island slotted inside a parent island_child_ssr/5 — child island with server-rendered initial HTML
Dataflow helpers (for template use): island_with_dataflow/3 — island with explicit dataflow string island_ssr_with_dataflow/4 — island with SSR content and explicit dataflow string child_island/4 — child island with SSR content
Hydration strategy variants: island_with_strategy/3 — specify eager/lazy/on-visible/on-idle island_ssr_with_strategy/4
Example (in a controller template):
let counter_html = IslandView.island_ssr("Counter", "{\"count\":0}", Counter.render("{\"count\":0}"))
let scripts = IslandView.scripts()
"<html><body>" ++ counter_html ++ scripts ++ "</body></html>"See also: island_socket.march, island_assets.march, islands.march.
Functions
Render a child island with SSR content and a parent reference.
A convenience wrapper for the common case of a child island with initial
server-rendered HTML and a parent binding. Uses Server dataflow (children
are always Server-dataflow relative to their parent).
Parameters:
name — child island module name
parent_id — parent island instance ID
state_json — initial state JSON (derived from parent state)
inner_html — server-rendered inner HTMLRender a Client-mode island placeholder with initial state.
The JS runtime attaches event listeners and routes data-on-* events
to the island's local update function.Render a child island placeholder slotted inside a parent.
The JS runtime uses data-march-parent to walk up the tree when the child
dispatches an event. The parent's handle_child_event is called with the
event name and payload JSON.
Parameters:
name — child island module name
parent_id — parent's data-march-instance-id value
on_event — event handler name registered on the parent
state_json — initial state JSON (derived from parent state)Render a child island with server-rendered initial HTML.
Render a Server-mode island placeholder.
The JS runtime will not attach any event listeners to this island.
Use Server mode for display-only islands like live feeds, scoreboards, etc.Render a Server-mode island with server-rendered inner HTML.
The inner_html is shown immediately; the JS runtime takes over on hydration
and patches the DOM as the server pushes new state.Render a Client-mode island with server-rendered initial HTML.
The inner_html is displayed immediately while the WASM module loads.
On hydration the runtime takes over and patches the DOM as state changes.Render a Client-mode island with SSR content wired to a channel.
Render an island with SSR content and an explicit dataflow string.
dataflow should be "client" or "server".Render a Client-mode island with SSR content and a hydration strategy.
Render a Client-mode island wired to a channel for state sync.
After each local update, the JS runtime pushes the new state JSON to the
channel topic. The channel can push state down at any time (last-write-wins).
Without a channel, use island/2 for purely local state.
Example:
IslandView.island_with_channel("Counter", state_json, "counter:#{user_id}")Render an island placeholder with an explicit dataflow string.
dataflow should be "client" or "server".Render a Client-mode island placeholder with a hydration strategy.
strategy is one of: "eager", "lazy", "on-visible", "on-idle".Generate the script tag that loads the island client runtime.
Include this in your layout <head> or before </body>.
Uses the default Bastion assets path.Generate the island runtime script tag with a custom base URL.
Example:
IslandView.scripts_with_base("/assets")
-- produces: <script src="/assets/islands.js"></script>Generate the WebSocket connection script tag.
This script connects to the island WebSocket endpoint and wires up
the bidirectional message loop. Include after scripts().Generate the WebSocket script tag with a custom base URL.