travels3.0

Travels Documentation

Learn, integrate, and operate patch-based undo/redo with Travels 3.

Travels is a framework-agnostic state history engine for durable undo/redo. It records forward and inverse JSON Patches, so applications with large state and small, frequent edits can retain compact timelines, persist them, and restore them later.

Write updates with familiar mutation syntax. Travels uses Mutative to produce immutable state by default, while mutable mode and controlled journals support reactive stores and externally owned state.

Travels 3

Version 3 uses explicit factories, one atomic persistence restore path, read-only shared views, and separate capabilities for state-owning timelines and external journals. Upgrading? Start with the Migration Guide.

Start with your goal

A complete example in one minute

import { createTravels, restoreTravels } from 'travels';

const travels = createTravels(
  { title: 'Untitled', tags: [] as string[] },
  { maxHistory: 100 }
);

const unsubscribe = travels.subscribe(({ state, position }) => {
  render(state, position);
});

travels.setState(
  (draft) => {
    draft.title = 'My document';
    draft.tags.push('draft');
  },
  { label: 'Edit document' }
);

travels.back();    // Undo the whole edit
travels.forward(); // Redo it

const snapshot = travels.serialize();
const restored = restoreTravels(snapshot);

The next step is the Quick Start, which explains each part of this flow.

When Travels is a good fit

Travels is optimized for history size, persistence, and replayable operation logs. It is especially useful for visual editors, form builders, local-first applications, workflow designers, and other editing experiences where users need a safe way to explore.

Your priorityRecommended approach
Large state, small updates, long retained historyTravels
Persist or transmit undo/redo historyTravels
Small state, short local-only history, lowest update latencyA snapshot stack may be simpler and faster
Concurrent multi-user conflict resolutionUse a CRDT/OT system; Travels alone does not resolve conflicts
Full-state replacement on every updateCompare snapshot and patch costs for your workload

See Choosing Travels for the full trade-off discussion.

The public building blocks

  • createTravels() creates a timeline that owns state updates.
  • createPatchableTravels() adds compile-time and immediate runtime checks for durable state.
  • createTravelJournal() records patch pairs from an external state owner.
  • restoreTravels() and restoreTravelJournal() restore complete validated snapshots.
  • Travels.deserialize() decodes, migrates, and validates persisted input.
  • getControls() exposes a narrow, read-only navigation surface for UI components.

All exports are documented in the API Reference.

Project resources

Travels is MIT licensed and written in TypeScript. Find runnable examples in the documentation’s Examples page, or browse the GitHub repository. The official bindings are use-travel for React and zustand-travel for Zustand.

On this page