lightspeed/stream

LiveView-style stream compatibility helpers.

Types

Stream

opaque

Streaming collection state for one target container.

pub opaque type Stream

One stream entry keyed by stable id.

pub type StreamItem {
  StreamItem(id: String, html: String)
}

Constructors

  • StreamItem(id: String, html: String)

Stream operation options compatible with LiveView semantics.

pub type StreamOptions {
  StreamOptions(at: Int, limit: option.Option(Int), reset: Bool)
}

Constructors

Values

pub fn entries(stream_state: Stream) -> List(StreamItem)

Current entries in render order.

pub fn item(id: String, html: String) -> StreamItem

Build one stream item.

pub fn new(target: String) -> Stream

Create a new empty stream state for a target container.

pub fn options() -> StreamOptions

Default stream options:

  • at: -1 (append)
  • limit: none
  • reset: false
pub fn stream(
  stream_state: Stream,
  incoming: List(StreamItem),
  options: StreamOptions,
) -> #(Stream, List(diff.Patch))

Apply stream/4 semantics.

pub fn stream_delete(
  stream_state: Stream,
  entry_id: String,
) -> #(Stream, List(diff.Patch))

Apply stream_delete/2 semantics.

pub fn stream_insert(
  stream_state: Stream,
  entry: StreamItem,
  at: Int,
  limit: option.Option(Int),
) -> #(Stream, List(diff.Patch))

Apply stream_insert/4 semantics.

pub fn target(stream_state: Stream) -> String

Current target selector.

pub fn with_at(options: StreamOptions, at: Int) -> StreamOptions

Override insertion position.

pub fn with_limit(
  options: StreamOptions,
  limit: Int,
) -> StreamOptions

Override stream limit. Positive keeps first N; negative keeps last N.

pub fn with_reset(
  options: StreamOptions,
  reset: Bool,
) -> StreamOptions

Override reset behavior.

Search Document