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

feat: change QueryHandler to contain QueryOne and QueryAll methods #6218

Merged
merged 12 commits into from Jul 17, 2020

Conversation

johanbay
Copy link
Collaborator

Extends #5753 with support for registering both $ and $$ handlers under the same selection prefix, i.e myCustomQueryHandlerPrefix/<selector>.

@mathiasbynens mathiasbynens requested a review from OrKoN July 14, 2020 09:13
Copy link
Contributor

@paullewis paullewis left a comment

Choose a reason for hiding this comment

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

Generally LGTM, but I'll await Mathias' approval.

src/common/DOMWorld.ts Outdated Show resolved Hide resolved
src/common/JSHandle.ts Outdated Show resolved Hide resolved
src/common/JSHandle.ts Outdated Show resolved Hide resolved
@johanbay johanbay marked this pull request as ready for review July 15, 2020 18:59
src/common/JSHandle.ts Outdated Show resolved Hide resolved
test/elementhandle.spec.ts Outdated Show resolved Hide resolved
@googlebot
Copy link

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.
In order to pass this check, please resolve this problem and then comment @googlebot I fixed it.. If the bot doesn't comment, it means it doesn't think anything has changed.

ℹ️ Googlers: Go here for more info.

@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

Co-authored-by: Mathias Bynens <mathias@qiwi.be>
Copy link
Collaborator

@hanselfmu hanselfmu left a comment

Choose a reason for hiding this comment

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

LGTM, thanks Johan!

@@ -34,7 +35,7 @@ export function registerCustomQueryHandler(
if (!isValidName)
throw new Error(`Custom query handler names may only contain [a-zA-Z]`);

_customQueryHandlers.set(name, handler as QueryHandler);
Copy link
Collaborator

Choose a reason for hiding this comment

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

nice work getting rid of this as :)

divs.map((d) => d.textContent).join('')
);
expect(txtContents).toBe('textcontent');
});
Copy link
Collaborator

Choose a reason for hiding this comment

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

nice tests!

Copy link
Collaborator

@jackfranklin jackfranklin left a comment

Choose a reason for hiding this comment

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

This LGTM with one question about the change of type to Function and if we can avoid it.

@johanbay
Copy link
Collaborator Author

Summary of changes:
The experimental API for registering custom query handlers is slightly changed such that one registers query handlers containing two strategies: one for querying a single element and one for querying all matching elements.

The api for custom query handlers is unchanged:

__experimental_registerCustomQueryHandler(name: string, queryHandler: QueryHandler): void;
__experimental_unregisterCustomQueryHandler(name: string): void;
__experimental_customQueryHandlers(): Map<string, QueryHandler>;
__experimental_clearQueryHandlers(): void;

but QueryHandler is now defined as

export interface QueryHandler {
  queryOne?: (element: Element | Document, selector: string) => Element | null;
  queryAll?: (element: Element | Document, selector: string) => Element[] | NodeListOf<Element>;
}

@mathiasbynens
Copy link
Member

Discussed with Paul offline. He's fine with this, so not blocking on his review+ bit.

@mathiasbynens mathiasbynens merged commit 313774c into puppeteer:main Jul 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants