MCPcopy Create free account
hub / github.com/editablejs/editable / deepEquals

Function deepEquals

packages/yjs-transform/src/object.ts:35–64  ·  view source on GitHub ↗
(node: InspectableObject, another: InspectableObject)

Source from the content-addressed store, hash-verified

33// Slates deep equality function: https://github.com/ianstormtaylor/slate/blob/68aff89e892fe15a16314398ff052ade6068900b/packages/slate/src/utils/deep-equal.ts#L13
34// We have to match slates deepEquals behavior to merge insert deltas in the same way slate does.
35export function deepEquals(node: InspectableObject, another: InspectableObject): boolean {
36 // eslint-disable-next-line guard-for-in
37 for (const key in node) {
38 const a = node[key]
39 const b = another[key]
40
41 if (isPlainObject(a) && isPlainObject(b)) {
42 if (!deepEquals(a, b)) {
43 return false
44 }
45 } else if (Array.isArray(a) && Array.isArray(b)) {
46 if (a.length !== b.length) return false
47 for (let i = 0; i < a.length; i++) {
48 if (a[i] !== b[i]) {
49 return false
50 }
51 }
52 } else if (a !== b) {
53 return false
54 }
55 }
56
57 for (const key in another) {
58 if (node[key] === undefined && another[key] !== undefined) {
59 return false
60 }
61 }
62
63 return true
64}
65
66export function pick<TObj extends Record<string, any>, TKeys extends keyof TObj>(
67 obj: TObj,

Callers 2

normalizeInsertDeltaFunction · 0.90
applyDeltaFunction · 0.90

Calls 1

isPlainObjectFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…