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
Install and build a timeline
Requirements, package installation, and a minimal working example.
Understand the history model
State, patches, positions, archives, branches, and baselines.
Connect your framework
React, Vue, Zustand, MobX, Pinia, forms, and external stores.
Persist complete histories
Serialize, validate, restore, migrate, and recover timeline snapshots.
Learn advanced behavior
Transactions, manual archives, events, mutable state, and journals.
Look up an exact API
Every exported function, class, interface, type alias, and variable.
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 priority | Recommended approach |
|---|---|
| Large state, small updates, long retained history | Travels |
| Persist or transmit undo/redo history | Travels |
| Small state, short local-only history, lowest update latency | A snapshot stack may be simpler and faster |
| Concurrent multi-user conflict resolution | Use a CRDT/OT system; Travels alone does not resolve conflicts |
| Full-state replacement on every update | Compare 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()andrestoreTravelJournal()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.