Skip to Content
DocsConceptsTransaction Model

Transaction Model

Quick Reference

Loro transactions are NOT database ACID transactions. They are operation bundling mechanisms for event emission.

Key Concepts

  • Purpose: Bundle related operations and control event emission
  • No rollback: Failed operations don’t undo previous ones
  • Event batching: Single event for all operations in transaction
  • History grouping: Operations stay together for undo/redo

Basic Usage

const = new (); // Without transaction - multiple events const = .("text"); .(0, "Hello"); .(); // Event emitted .(5, " World"); .(); // Another event

How Transactions Work

Pending Operations

Local operations are pending by default and won’t emit events until committed:

const = new (); const = .("text"); // Operation is pending, no event emitted yet .(0, "Hello"); // Explicit commit triggers event emission .();

Implicit Commits

Certain operations trigger implicit commits automatically:

const = new (); const = .("text"); .(0, "Hello"); // Pending operation // These operations trigger implicit commit: .(); // Implicit commit before import // or .(.()); // Implicit commit before checkout // or .({ : "update" }); // Implicit commit before export

Transaction Guarantees

  • All operations share the same timestamp (if enabled)
  • Operations grouped in a single Change
  • One event emitted after transaction completes
  • Operations committed together at transaction end
  • Before committing, the local edits are not synced to other peers
Last updated on