Skip to content

Commit

Permalink
Remove dequal as a dep from the project.
Browse files Browse the repository at this point in the history
Inspection of the code and types showed that the actual check does not need to handle all cases, but rather there is a small handful of attributes and cases to check. As such do it in the project and remove the entire need for a dep.

Ref: #354
  • Loading branch information
samccone authored and ljharb committed Jun 23, 2024
1 parent 3f4caed commit 39030e7
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 22 deletions.
3 changes: 0 additions & 3 deletions flow/dequal.js

This file was deleted.

17 changes: 1 addition & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,5 @@
"ie 11"
],
"dependencies": {
"dequal": "^2.0.3"
}
}
29 changes: 27 additions & 2 deletions src/elementAXObjectMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* @flow
*/

import { dequal } from 'dequal/lite';
import AXObjects from './AXObjectsMap';
import iterationDecorator from './util/iterationDecorator';

Expand Down Expand Up @@ -48,6 +47,32 @@ for (let [name, def] of AXObjects.entries()) {
}
}

function deepAxObjectModelRelationshipConceptAttributeCheck(a?: Array<AXObjectModelRelationConceptAttribute>, b?: Array<AXObjectModelRelationConceptAttribute>) {
if (a === undefined && b !== undefined) {
return false;
}

if (a !== undefined && b === undefined) {
return false;
}

if (a !== undefined && b !== undefined) {
if (a.length != b.length) {
return false;
}

// dequal checks position equality
// https://github.com/lukeed/dequal/blob/5ecd990c4c055c4658c64b4bdfc170f219604eea/src/index.js#L17-L22
for (let i = 0; i < a.length; i++) {
if (b[i].name !== a[i].name || b[i].value !== a[i].value) {
return false;
}
}
}

return true;
}

const elementAXObjectMap: TAXObjectQueryMap<
TElementAXObjects,
AXObjectModelRelationConcept,
Expand All @@ -66,7 +91,7 @@ const elementAXObjectMap: TAXObjectQueryMap<
},
get: function (key: AXObjectModelRelationConcept): ?Array<AXObjectName> {
const item = elementAXObjects.find(tuple => (
key.name === tuple[0].name && dequal(key.attributes, tuple[0].attributes)
key.name === tuple[0].name && deepAxObjectModelRelationshipConceptAttributeCheck(key.attributes, tuple[0].attributes)
));
return item && item[1];
},
Expand Down

0 comments on commit 39030e7

Please sign in to comment.