Skip to content

Commit

Permalink
Remove dequal dep from the project.
Browse files Browse the repository at this point in the history
Unroll the equality check inside of the file for the specifc type comparision.
  • Loading branch information
samccone committed Jul 4, 2024
1 parent 431ad28 commit 6af53ca
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 25 deletions.
3 changes: 0 additions & 3 deletions flow/dequal.js

This file was deleted.

16 changes: 0 additions & 16 deletions package-lock.json

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

5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,5 @@
"not dead",
"not op_mini all",
"ie 11"
],
"dependencies": {
"dequal": "^2.0.3"
}
]
}
51 changes: 49 additions & 2 deletions src/elementRoleMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* @flow
*/

import { dequal } from 'dequal/lite';
import iterationDecorator from "./util/iterationDecorator";
import rolesMap from './rolesMap';

Expand Down Expand Up @@ -49,7 +48,7 @@ const elementRoleMap: TAriaQueryMap<
},
get: function (key: ARIARoleRelationConcept): ?RoleSet {
const item = elementRoles.find(tuple => (
key.name === tuple[0].name && dequal(key.attributes, tuple[0].attributes)
key.name === tuple[0].name && ariaRoleRelationConceptAttributeEquals(key.attributes, tuple[0].attributes)
));
return item && item[1];
},
Expand All @@ -64,6 +63,54 @@ const elementRoleMap: TAriaQueryMap<
},
};

function ariaRoleRelationConceptAttributeEquals(
a?: Array<ARIARoleRelationConceptAttribute>,
b?: Array<ARIARoleRelationConceptAttribute>,
): boolean {

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;
}

for (let i = 0; i < a.length; i++) {
if (a[i].name !== b[i].name || a[i].value !== b[i].value) {
return false;
}

if (a[i].constraints === undefined && b[i].constraints !== undefined) {
return false;
}

if (a[i].constraints !== undefined && b[i].constraints === undefined) {
return false
}

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

for (let j = 0; j < a[i].constraints.length; j++) {
if (a[i].constraints[j] !== b[i].constraints[j]) {
return false;
}
}
}
}
}

return true;
}

export default (
iterationDecorator(
elementRoleMap,
Expand Down

0 comments on commit 6af53ca

Please sign in to comment.