timetravel

Development-only model history and inspection for Lustre applications.

Types

Stable labels and value formatting for production-minified builds.

JavaScript minifiers rename Gleam constructor classes, so applications that ship the inspector in a minified bundle should provide formatters based on Gleam pattern matching rather than JavaScript constructor names.

pub type Formatters(model, app_message) {
  Formatters(
    message_name: fn(app_message) -> String,
    format_message: fn(app_message) -> String,
    format_model: fn(model) -> String,
  )
}

Constructors

  • Formatters(
      message_name: fn(app_message) -> String,
      format_message: fn(app_message) -> String,
      format_model: fn(model) -> String,
    )

Messages handled by the time-travel wrapper.

pub type Message(app_message) {
  App(app_message)
  Back
  Forward
  ReturnToPresent
  GoTo(Int)
  ToggleInspector
}

Constructors

  • App(app_message)
  • Back
  • Forward
  • ReturnToPresent
  • GoTo(Int)
  • ToggleInspector

The wrapped application model and its recorded history.

past is stored newest-first so recording and stepping backward are cheap. future is stored with the next state first. Together they form the full timeline around current.

pub opaque type Model(model, app_message)

Values

pub fn application(
  app_init: fn(arguments) -> #(model, effect.Effect(app_message)),
  app_update: fn(model, app_message) -> #(
    model,
    effect.Effect(app_message),
  ),
  app_view: fn(model) -> element.Element(app_message),
) -> lustre.App(
  arguments,
  Model(model, app_message),
  Message(app_message),
)

Wrap an existing Lustre application with development-only time travel.

pub fn application_with_formatters(
  app_init: fn(arguments) -> #(model, effect.Effect(app_message)),
  app_update: fn(model, app_message) -> #(
    model,
    effect.Effect(app_message),
  ),
  app_view: fn(model) -> element.Element(app_message),
  formatters: Formatters(model, app_message),
) -> lustre.App(
  arguments,
  Model(model, app_message),
  Message(app_message),
)

Wrap an application using minification-safe message labels and formatters.

pub fn current(model: Model(model, app_message)) -> model

Return the application model at the selected point in history.

pub fn init(
  arguments arguments: arguments,
  with app_init: fn(arguments) -> #(
    model,
    effect.Effect(app_message),
  ),
) -> #(
  Model(model, app_message),
  effect.Effect(Message(app_message)),
)

Initialise a time-travel model using an application’s init function.

pub fn position(model: Model(model, app_message)) -> #(Int, Int)

Return the selected and latest zero-based timeline positions.

pub fn update(
  model model: Model(model, app_message),
  message message: Message(app_message),
  with app_update: fn(model, app_message) -> #(
    model,
    effect.Effect(app_message),
  ),
) -> #(
  Model(model, app_message),
  effect.Effect(Message(app_message)),
)

Update a time-travel model using an application’s update function.

pub fn view(
  model model: Model(model, app_message),
  app app_view: fn(model) -> element.Element(app_message),
) -> element.Element(Message(app_message))

Render an application together with the time-travel inspector.

pub fn view_with_formatters(
  model model: Model(model, app_message),
  app app_view: fn(model) -> element.Element(app_message),
  formatters formatters: Formatters(model, app_message),
) -> element.Element(Message(app_message))

Render the wrapped application using custom inspection formatters.

Search Document