Skip to content

Core concepts

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

Previous: Overview · Next: Tutorial

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 UIsserialize(result, "markdown" | "json" | …)

Snapshots and change records

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

const result = diff(before, after);
// result.changes[] — path, type (add|update|remove), value, oldValue

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)Equality + path detailTests
patch(diffResult)JSON Patch opsNetwork sync, undo stacks
applyPatch(target, ops)New objectApply remote or local updates
serialize(result, format)StringLogs, exports, docs

Change record fields

FieldMeaning
pathDot/bracket path (e.g. user.name)
typeupdate, add, or remove
valueValue after change
oldValueValue before change (updates/removes)

Next steps

GoalGuide
First integrationTutorial
Diff optionsDiffing
Patch apply/revertPatching

Diff explorer →

JOC is a JayOnCode monorepo of @jayoncode/* packages. Docs sync from source via TypeDoc and sync scripts.