libero/ssr
Helpers for server-side rendering with Libero.
Server-side: call a dispatch handler directly, encode flags for the HTML document, and render the full page shell.
Client-side: read and decode flags embedded by the server.
Types
Values
pub fn call(
handle handle: fn(state, BitArray) -> #(
BitArray,
option.Option(error.PanicInfo),
state,
),
state state: state,
module module: String,
msg msg: msg,
expect expect: fn(response) -> payload,
) -> Result(payload, SsrError)
Call a dispatch handler directly on the server, returning a
decoded payload. Encodes the call envelope, invokes the handler,
strips the wire framing, and passes the MsgFromServer response
through the expect function to extract the desired value.
The expect parameter works like Elm’s Http.expect — you tell
the call how to unwrap the response variant into the value you
actually want:
ssr.call(
handle: dispatch.handle,
state:,
module: "shared/messages",
msg: GetCounter,
expect: fn(resp) {
let assert CounterUpdated(Ok(n)) = resp
n
},
)
// Returns Result(Int, SsrError)
pub fn decode_flags(
flags: dynamic.Dynamic,
) -> Result(a, SsrError)
Decode flags from a Dynamic value (base64 ETF string). Use this in a Lustre init function to decode server-embedded flags.
pub fn document(
title title: String,
body body: String,
flags flags: String,
client_module client_module: String,
) -> String
Generate a complete HTML document with a pre-rendered body, embedded flags, and a client module import.
pub fn encode_flags(data: a) -> String
Encode a value as a base64 ETF string, ready to embed in HTML as client flags.