Skip to content

Core concepts

Terminology and data flow for @jayoncode/object-diff.

Previous: Overview · Next: Tutorial

Glossary

TermMeaning
ChangeOne typed record from diff() (path, type, values)
DiffResult{ changes, metadata } returned by diff
PatchRFC 6902 operations derived from a DiffResult (patch())
MergeCombine two/three snapshots with strategy + conflicts (/merge)
QueryFilter/summarize an existing DiffResult without re-diffing (/query)
ViewFluent toolbox over a DiffResult — explain / filter / serialize / patch (/view)

Problem → approach

Manual comparisonWith Object Diff
JSON.stringify(a) !== JSON.stringify(b) — no paths, false positives on key orderdiff(a, b) — typed change records with paths
Hand-rolled patch objects for every APIpatch(result) — RFC 6902 operations from any diff
Full re-send of large state on every editapplyPatch(target, ops) — minimal updates
Custom formatters for audit UIscreateDiffView(result).explain() / serialize(...)

Snapshots and change records

ts
import { diff } from "@jayoncode/object-diff";

const before = { user: { name: "John" }, count: 1 };
const after = { user: { name: "Jane" }, count: 1 };

const result = diff(before, after);
// result.changes[] — { path, type, previous?, current?, from? }
// result.metadata — counts including movedCount

Change record fields

FieldMeaning
pathDisplay path (e.g. user.name, items[0])
typeadded | removed | changed | unchanged | moved
previousValue before the change — key is omitted entirely when undefined
currentValue after the change — key is omitted entirely when undefined
fromSource path when type is moved

Equality & supported types

diff()/compare() go well beyond JSON.stringify equality: Object.is semantics for primitives (NaN equals NaN), Date by getTime(), RegExp by source+flags, Map/Set by deep-equal contents, typed arrays by bytes, and functions by ===. Plain objects and arrays are compared recursively, key by key. Full rules and edge cases: Equality & supported types in the Diffing guide.

API map

APIReturnsUse when
diff(a, b)Change records + metadataAudit, debug, UI diff viewers
hasChanges(a, b)booleanDirty flags, skip expensive work
compare(a, b)Deep equalityTests, custom equality
patch(diffResult)JSON Patch opsNetwork sync, undo stacks
applyPatch(target, ops)New objectApply remote or local updates
serialize(result, format)StringLogs, exports, docs

Optional engines live on subpaths (/merge, /query, /stats, /view, …) — see Engines.

Next steps

GoalGuide
First integrationTutorial
Diff optionsDiffing
Patch apply / RFC opsPatching

Diff explorer →

An ecosystem of independent, headless TypeScript libraries engineered for modern web development. Every package includes interactive playgrounds and documentation that evolves alongside the code.