travels3.0
Reference

Configuration Options

Reference for timeline creation, restore, persistence, patches, hooks, and Mutative options.

Factory overloads infer archive mode and patch options from the options you provide. The exact generated types are available under TravelsOptions and RestoreTravelsOptions.

Timeline options

OptionTypeDefaultPurpose
maxHistorynumber10Maximum retained patch entries; must be a non-negative integer.
autoArchivebooleantrueArchive every effective update automatically, or expose manual archive() controls.
mutablebooleanfalseApply patches to the live object for identity-sensitive reactive stores.
warnOnUnsupportedStatebooleantrue in developmentEnable compatibility diagnostics for state, patches, paths, and metadata.
patchesOptionsPatchesOption{}Customize patch representation, including pathAsArray; patches cannot be disabled.
enableAutoFreezebooleanfalseFreeze produced immutable states; incompatible with mutable: true.
strictMutative strict optionfalseMatch Mutative’s stricter immutability behavior.
markMutative mark optionMutative defaultCustomize which objects Mutative treats as immutable/draftable.

See the Mutative documentation for the underlying strict, mark, and auto-freeze semantics. When persisted history was recorded with custom strict or mark, pass matching values through replayOptions during semantic deserialization.

Observer and lifecycle hooks

OptionSignature inputWhen it runs
devtoolsTravelsEvent<S, P>After each committed event, alongside subscribers.
onErrorWrapped core ErrorWhen Travels reports a core operation failure; nested transaction errors settle at the root.
onBranchDiscard{ position, discarded }After a committed edit removes redo entries.
onWarning{ code, message }For non-fatal normalization, compatibility, position, and history warnings.
onObserverError{ source, error }When a listener or lifecycle/diagnostic hook throws after commit.

Observer errors do not roll back committed transitions. Hook functions should not synchronously mutate the same timeline.

Restore options

restoreTravels(snapshot, options?) accepts applicable creation options but deliberately does not accept a separate initialState or history; the complete snapshot is the atomic state/history input.

In 3.0.1, the factory takes a snapshot object and ignores a directly supplied validation option. To verify an object or JSON string, use restoreTravels(Travels.deserialize<State>(stored, { validation: 'semantic' })).

The next 3.x minor (unreleased) adds direct JSON string input and a validation: 'semantic' restore option. With that option, Travels checks the complete history using the restore's strict and mark settings before updating a target or trimming history.

For mutable integration, it additionally accepts:

const restored = restoreTravels(snapshot, {
  mutable: true,
  target: reactiveStore,
});

target must be a compatible object or array root and requires mutable: true. Travels overwrites it in place with detached snapshot state. restoreTravelJournal(snapshot, { apply, ...options }) instead requires the external owner’s synchronous navigation callback and does not expose state-owning mutable options.

Serialization options

travels.serialize({ strict: true });

strict rejects any current state, retained patch value/path, or metadata that cannot round-trip through the documented JSON persistence contract. Use assertPersistenceCompatible() when validation should happen without creating a snapshot.

Deserialization options

OptionPurpose
validation'structural' by default; 'semantic' additionally replays and reverses reachable entries.
fallbackA snapshot or synchronous factory used after detected parse/migration/validation failure.
migrateA synchronous callback that converts old input into the current snapshot schema.
onErrorReceives TravelsPersistenceError before fallback or throw.
replayOptionsMatching Mutative strict and mark settings for semantic replay.

All storage, network, decompression, and application-envelope verification work belongs before the synchronous deserialization call.

Capability-specific options

  • createTravels() owns updates and supports mutable, tracking, transactions, and controls.
  • createPatchableTravels() accepts the durable state contract and validates initial state immediately.
  • createTravelJournal() requires apply and rejects state-owning mutable options.
  • Automatic timelines omit archive() and canArchive(); manual factories expose them in runtime and TypeScript.

These distinctions fail closed instead of silently ignoring ownership-specific options.

On this page