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

Use xpath query handler #2230

Merged
merged 3 commits into from
Jun 13, 2023
Merged

Use xpath query handler #2230

merged 3 commits into from
Jun 13, 2023

Conversation

kblok
Copy link
Member

@kblok kblok commented Jun 12, 2023

closes #2085

@kblok kblok force-pushed the use-xpath-query-handler branch from eca6400 to dc8e037 Compare June 12, 2023 17:09
@kblok kblok merged commit 6ecce37 into master Jun 13, 2023
@kblok kblok deleted the use-xpath-query-handler branch June 13, 2023 16:16

if (!_queryHandlers.TryGetValue(name, out var queryHandler))
foreach (var kv in handlers)
Copy link
Contributor

Choose a reason for hiding this comment

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

Use 4 spaces instead of 2 🧹

Copy link
Member Author

Choose a reason for hiding this comment

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

ohhh just merged! Let's create a follow up PR

Copy link
Contributor

Choose a reason for hiding this comment

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

I'll create a PR right away

Copy link
Member Author

Choose a reason for hiding this comment

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

I have one ready to go :)

@@ -10,6 +10,8 @@ namespace PuppeteerSharp
{
internal class CustomQueriesManager
{
private static readonly string[] CustomQuerySeparators = new[] { "=", "/" };
private readonly Dictionary<string, PuppeteerQueryHandler> _internalQueryHandlers;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestion:
Besides _defaultHandler, we don't need to store the internal handlers in separate fields as they are only used in the constructor to initialize _internalQueryHandlers.

By changing them from fields to private static creator methods, we can move initialization of _internalQueryHandlers to declaration and remove the then empty public constructor.

private readonly Dictionary<string, PuppeteerQueryHandler> _internalQueryHandlers = new()
{
    ["aria"] = AriaHandler(),
    ["pierce"] = PierceHandler(),
    ["text"] = TextQueryHandler(),
    ["xpath"] = XpathHandler(),
};

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

Successfully merging this pull request may close these issues.

Add missing Xpath Selector engine
2 participants