lattice_text

Plain-text CRDT for Gleam using YATA-style left/right origins.

Use this package when replicas need to edit shared text concurrently and converge without coordination. All operations are grapheme-based, so emoji and combining sequences count as one unit. For a generic list CRDT, use lattice_sequence directly.

Installation

gleam add lattice_text

Quick example

import lattice_core/replica_id
import lattice_text/text

pub fn main() {
  let local = replica_id.new("node-a")
  let assert Ok(node_a) =
    text.new(local)
    |> text.insert(0, "Hello world")

  let assert Ok(node_b) =
    text.new(replica_id.new("node-b"))
    |> text.append("!")

  let merged = text.merge(node_a, node_b, local)

  text.value(merged)
  // -> "Hello world!"
}

Modules

ModulePurpose
lattice_text/textGrapheme-based text CRDT with editing, range, and delta operations.

Notes

Map composition

lattice_maps/crdt.TextSpec creates an empty Text child. Use ORMap when concurrent child edits must merge; use its sparse callback with the delta from a Text *_with_delta operation to avoid sending the full document. This remains sparse through nested ORMap paths.

Map re-addition creates a fresh generation with a new editing namespace. Newer generations replace older content. A LWWMap Text assignment instead replaces a whole snapshot and does not merge losing concurrent edits.

Text dispatch uses a distinct wrapper around this package’s unchanged Sequence JSON envelope. Do not infer Text from a bare Sequence envelope. Outer map clocks do not authorize inner sequence compaction.

Links

License

MIT

Search Document