From 7274cef10061f0b9c2c907b730589b4f221b2487 Mon Sep 17 00:00:00 2001 From: sanine Date: Sun, 5 Nov 2023 23:25:58 -0600 Subject: implement agent change conflict/merge detection --- src/util.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/util.js') diff --git a/src/util.js b/src/util.js index 8b85ba7..74233f4 100644 --- a/src/util.js +++ b/src/util.js @@ -21,3 +21,23 @@ export function pairs(arr1, arr2) { .map((x, i) => arr2.map(y => [x, y])) .flat(); } + + +export function deepEqual(a, b, debug=false) { + if (typeof(a) === 'object') { + if (typeof(b) === 'object') { + // do deep equality + return [...new Set(Object.keys(a).concat(Object.keys(b)))].reduce( + (acc, key) => { + return acc && deepEqual(a[key], b[key]); + }, + true + ); + } else { + // one object, one non-object + return false; + } + } else { + return a === b; + } +} -- cgit v1.2.1