Skip to content
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

misc: use typed-query-selector for native querySelector #11990

Merged
merged 2 commits into from
Jan 23, 2021

Conversation

brendankenny
Copy link
Member

Follow up to #11526, expands the use of typed-query-selector to uses of querySelector/querySelectorAll outside of uses of dom.find/dom.findAll. Allows removal of a few more type casts.

@brendankenny brendankenny requested a review from a team as a code owner January 22, 2021 21:25
@brendankenny brendankenny requested review from adamraine and removed request for a team January 22, 2021 21:25
@google-cla google-cla bot added the cla: yes label Jan 22, 2021
@brendankenny brendankenny requested review from connorjclark and removed request for adamraine January 22, 2021 21:26
.filter(/** @return {tag is HTMLLinkElement} */ tag => {
if (tag.tagName !== 'LINK') return false;

.filter(linkTag => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removing the lines in this file is real nice

@@ -184,7 +184,7 @@ class CategoryRenderer {
this.dom.find('.lh-category-header__description', tmpl).appendChild(descEl);
}

return /** @type {Element} */ (tmpl.firstElementChild);
return tmpl;
Copy link
Member Author

@brendankenny brendankenny Jan 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not a querySelector simplification, but you can appendChild a DocumentFragment. Not sure why we bothered with passing back the first child here since this is equivalent.

*/
_getNextSelectableNode(allNodes, startNode) {
const nodes = allNodes.filter((node) => {
const nodes = allNodes.filter(/** @return {node is HTMLElement} */ (node) => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also not querySelector related, but this was already checking instanceof HTMLElement, so it seems good

* @param {ParentNode} context
* @return {HTMLElement}
*/
function find(query, context) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we apparently have four copies of find() :)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

soon to be 5 with #11832

I often copy Dom in personal projects because the interface is so nice.

@@ -283,7 +282,7 @@ class LighthouseReportViewer {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.onload = function(e) {
const readerTarget = /** @type {?FileReader} */ (e.target);
const readerTarget = e.target;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

want to just remove the variable?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

want to just remove the variable?

oh good call

* @param {ParentNode} context
* @return {HTMLElement}
*/
function find(query, context) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

soon to be 5 with #11832

I often copy Dom in personal projects because the interface is so nice.

@@ -170,7 +170,7 @@ class CategoryRenderer {
/**
* @param {LH.ReportResult.Category} category
* @param {Record<string, LH.Result.ReportGroup>} groupDefinitions
* @return {Element}
* @return {DocumentFragment}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this just remain Element? I don't see benefit in making the return type more specific.

Copy link
Member Author

@brendankenny brendankenny Jan 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this just remain Element? I don't see benefit in making the return type more specific.

It would be a Node, not an Element, so it had to change either way

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants