-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Query API for alfa-dom
#1413
Query API for alfa-dom
#1413
Conversation
The function will populate and cache a map from id to element on first invocation
alfa-dom
alfa-dom
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work. Some small polish.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should also use the new cached map for aria-labelledby
resolution at
alfa/packages/alfa-aria/src/name.ts
Lines 890 to 903 in b1e42be
// Since there are a lot of elements in the document, but very few in the | |
// aria-labelledby, it is more efficient to grab them in DOM order (in a | |
// single traversal) and then sort by tokens order rather than grab the ids | |
// one by one in the correct order. | |
const references = root | |
.elementDescendants() | |
.filter(hasId(equals(...ids))) | |
.sortWith((a, b) => | |
Comparable.compareNumber( | |
// the previous filter ensure that the id exists | |
ids.indexOf(a.id.getUnsafe()), | |
ids.indexOf(b.id.getUnsafe()) | |
) | |
); |
There's also a follow up task on #1037 on getting rid of all usages of |
That's a bit different (I think). The So, I feel it's more about using the new map that replacing the |
Part of #1037
First attempt at creating a query API for querying the DOM. For now, two common queries has been extracted and put into the new
Query
namespace inalfa-dom
and the results are now cached which should give a slight performance improvement.