lustre_pipes/server_component

Functions

pub fn component() -> #(String, List(Attribute(a)))

Render the Lustre Server Component client runtime. The content of your server component will be rendered inside this element.

Note: you must include the lustre-server-component.mjs script found in the priv/ directory of the Lustre package in your project’s HTML or using the lustre.script() function.

pub fn data(
  server_component: #(String, List(Attribute(a))),
  json: Json,
) -> #(String, List(Attribute(a)))

Ocassionally you may want to attach custom data to an event sent to the server. This could be used to include a hash of the current build to detect if the event was sent from a stale client.

Your event decoders can access this data by decoding data property of the event object.

pub fn include(
  server_component: #(String, List(Attribute(a))),
  properties: List(String),
) -> #(String, List(Attribute(a)))

Properties of a JavaScript event object are typically not serialisable. This means if we want to pass them to the server we need to copy them into a new object first.

This attribute tells Lustre what properties to include. Properties can come from nested objects by using dot notation. For example, you could include the id of the target element by passing ["target.id"].

pub fn route(
  server_component: #(String, List(Attribute(a))),
  path: String,
) -> #(String, List(Attribute(a)))

The route attribute tells the client runtime what route it should use to set up the WebSocket connection to the server. Whenever this attribute is changed (by a clientside Lustre app, for example), the client runtime will destroy the current connection and set up a new one.

Search Document