retrace_frontend/capture

Optional capture coordination. Observe only application-approved transitions. Map the returned effects/messages into your application. They are not events to record. Stop the owned client when the application unmounts.

Types

pub type Info {
  Info(
    session: wire.Session,
    captured: Int,
    saved: Int,
    delivery: client.Status,
    failure: option.Option(String),
  )
}

Constructors

pub opaque type Message
pub opaque type State

Values

pub fn info(state: State) -> Info
pub fn observe(
  state: State,
  before: model,
  message: message,
  encode_model: fn(model) -> String,
  encode_message: fn(message) -> wire.Event,
) -> #(State, effect.Effect(Message))

Observe after accepting a transition, passing its state BEFORE reduction. This helper never runs application effects. Record their resulting messages through this same hook. A failure stops capture; your update still proceeds.

pub fn observe_projected(
  state: State,
  projection: Result(#(model, message), error),
  encode_model: fn(model) -> String,
  encode_message: fn(message) -> wire.Event,
) -> #(State, effect.Effect(Message))

Observe an application’s fallible safe projection of an accepted transition. The pair contains the safe state BEFORE the transition and its safe event. Only successful projections reach the codecs. Failure stops capture without recording the application’s error, which may itself contain private values. This does not classify data or prove the projection/codecs safe or pure.

pub fn retry(state: State) -> effect.Effect(Message)
pub fn session(
  user_ref: String,
  build: String,
  contract: String,
  platform: String,
) -> wire.Session

Start a new identity; every application instance needs a distinct session.

pub fn start(
  session: wire.Session,
  config: client.Config,
  storage: client.Storage,
  transport: client.Transport,
) -> Result(#(State, effect.Effect(Message)), retrace.Error(Nil))
pub fn start_with_clock(
  session: wire.Session,
  config: client.Config,
  storage: client.Storage,
  transport: client.Transport,
  clock: fn() -> Int,
) -> Result(#(State, effect.Effect(Message)), retrace.Error(Nil))

The clock returns elapsed milliseconds since this session began.

pub fn stop(state: State) -> effect.Effect(Message)

Run before discarding the application state. Persisted batches remain queued.

pub fn update(state: State, message: Message) -> State
✨ Search Document