diff options
author | sanine <sanine.not@pm.me> | 2023-11-05 23:25:58 -0600 |
---|---|---|
committer | sanine <sanine.not@pm.me> | 2023-11-05 23:25:58 -0600 |
commit | 7274cef10061f0b9c2c907b730589b4f221b2487 (patch) | |
tree | b76de2774429bdd69e01322233e9ae8b7b838a48 /src/util.js | |
parent | 639a559dd44d924c6b2e545c7d2eb28b11d4a314 (diff) |
implement agent change conflict/merge detection
Diffstat (limited to 'src/util.js')
-rw-r--r-- | src/util.js | 20 |
1 files changed, 20 insertions, 0 deletions
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;
+ }
+}
|