lightspeed/diff

Patch model and codec for rendered updates.

Types

Decode errors for patch streams.

pub type DecodeError {
  EmptyPayload
  UnknownPayloadTag(String)
  BadFieldCount(stage: String, expected: Int, actual: Int)
  InvalidInteger(String)
  UnsupportedVersion(Int)
  MissingDictionaryEntry(Int)
  MalformedOperation(String)
  InvalidEscapeSequence
}

Constructors

  • EmptyPayload
  • UnknownPayloadTag(String)
  • BadFieldCount(stage: String, expected: Int, actual: Int)
  • InvalidInteger(String)
  • UnsupportedVersion(Int)
  • MissingDictionaryEntry(Int)
  • MalformedOperation(String)
  • InvalidEscapeSequence

Dynamic text values injected into static markup by slot name.

pub type DynamicSlot {
  DynamicSlot(name: String, value: String)
}

Constructors

  • DynamicSlot(name: String, value: String)

Keyed nodes used for stable collection updates.

pub type KeyedNode {
  KeyedNode(key: String, html: String)
}

Constructors

  • KeyedNode(key: String, html: String)

Patch model.

pub type Patch {
  Replace(target: String, html: String)
  Append(target: String, html: String)
  Prepend(target: String, html: String)
  Remove(target: String)
  ReplaceSegments(
    target: String,
    fingerprint: String,
    static_html: String,
    dynamic_slots: List(DynamicSlot),
  )
  UpdateSegments(
    target: String,
    fingerprint: String,
    dynamic_slots: List(DynamicSlot),
  )
  UpsertKeyed(target: String, key: String, html: String)
  RemoveKeyed(target: String, key: String)
  ReorderKeyed(target: String, keys: List(String))
}

Constructors

  • Replace(target: String, html: String)
  • Append(target: String, html: String)
  • Prepend(target: String, html: String)
  • Remove(target: String)
  • ReplaceSegments(
      target: String,
      fingerprint: String,
      static_html: String,
      dynamic_slots: List(DynamicSlot),
    )
  • UpdateSegments(
      target: String,
      fingerprint: String,
      dynamic_slots: List(DynamicSlot),
    )
  • UpsertKeyed(target: String, key: String, html: String)
  • RemoveKeyed(target: String, key: String)
  • ReorderKeyed(target: String, keys: List(String))

Values

pub fn carries_html(patch: Patch) -> Bool

True when a patch carries HTML content.

pub fn decode(payload: String) -> Result(Patch, DecodeError)

Decode one patch from a versioned compressed stream.

pub fn decode_error_to_string(error: DecodeError) -> String

Stable error labels for logs and adapter failures.

pub fn decode_stream(
  payload: String,
) -> Result(List(Patch), DecodeError)

Decode a patch stream.

pub fn encode(patch: Patch) -> String

Encode one patch into a versioned compressed stream.

pub fn encode_stream(patches: List(Patch)) -> String

Encode a patch stream with dictionary compression.

pub fn keyed_node(key: String, html: String) -> KeyedNode

Build one keyed node.

pub fn keyed_patch_plan(
  target: String,
  previous: List(KeyedNode),
  current: List(KeyedNode),
) -> List(Patch)

Build a keyed update plan from previous and current collections.

pub fn operation(patch: Patch) -> String

Return the patch operation name.

pub const patch_stream_version: Int
pub fn slot(name: String, value: String) -> DynamicSlot

Build one dynamic slot value.

pub fn target(patch: Patch) -> String

Return the target selector or id for a patch.

Search Document