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

refactor(core): Add an ActionResolver option to Dispatcher. #55757

Closed

Conversation

tbondwilkinson
Copy link
Contributor

This will enable internal usages to migrate from ActionResolver in EventContract to ActionResolver in Dispatcher.

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • angular.io application / infrastructure changes
  • Other... Please describe:

@tbondwilkinson tbondwilkinson force-pushed the jsaction-action-resolver-3 branch 4 times, most recently from df38cbe to 372668e Compare May 11, 2024 21:23
@tbondwilkinson
Copy link
Contributor Author

TESTED=TGP

@tbondwilkinson
Copy link
Contributor Author

DIFFBASE=#55721

@tbondwilkinson tbondwilkinson marked this pull request as ready for review May 12, 2024 02:42
@pullapprove pullapprove bot added the requires: TGP This PR requires a passing TGP before merging is allowed label May 12, 2024
@tbondwilkinson tbondwilkinson requested review from rahatarmanahmed and removed request for ellenyuan May 12, 2024 02:42
@tbondwilkinson tbondwilkinson added action: review The PR is still awaiting reviews from at least one requested reviewer area: core Issues related to the framework runtime target: rc This PR is targeted for the next release-candidate core: event dispatch labels May 12, 2024
@ngbot ngbot bot added this to the Backlog milestone May 12, 2024
Copy link
Contributor

@AndrewKushnir AndrewKushnir left a comment

Choose a reason for hiding this comment

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

LGTM, just left a couple minor (non-blocking) comments.

Comment on lines +138 to +134
if (this.useActionResolver) {
this.actionResolver = new ActionResolver({
Copy link
Contributor

Choose a reason for hiding this comment

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

Just as an idea: I was thinking if we can make the ActionResolver tree-shakable and have a special function call that would bring the ActionResolver code, for example:

new EventContract(new EventContractContainerManager(), withActionResolver())

However, if we want to enable it by default (as we have it in this PR), the function would be referenced internally within the EventContract class anyways and ActionResolver would remain non-tree-shakable.

This is not a blocker for the PR, just an idea that I wanted to share.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The way this written is intentionally for dead-code-elimination with JSCompiler.

I had previously tried:

  constructor(
    containerManager: EventContractContainerManager,
    private readonly actionResolver: ActionResolver | null = new ActionResolver(),
)

But JSCompiler could not remove that, because it wasn't sure based on the callsite that passed null that it was actually unused. JSCompiler does a very good job of inferring what can be deleted when the code to be deleted is wrapped in boolean, but a much worse job when the parameter is a more complex type.

So I believe withActionResolver() would not appropriately DCE, based on my explorations. I could be misunderstanding what you're proposing though.

Comment on lines +174 to +167
if (this.useActionResolver) {
this.actionResolver!.resolve(eventInfo);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

nit:

Suggested change
if (this.useActionResolver) {
this.actionResolver!.resolve(eventInfo);
}
this.actionResolver?.resolve(eventInfo);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Likewise, this is specifically for DCR - the boolean allows JSCompiler to appropriately inline the value as constant and then remove the code.

@pullapprove pullapprove bot requested review from atscott and dylhunn May 12, 2024 22:09
Copy link
Member

@pkozlowski-opensource pkozlowski-opensource left a comment

Choose a reason for hiding this comment

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

LGTM

Reviewed-for: public-api

Copy link
Contributor

@rahatarmanahmed rahatarmanahmed left a comment

Choose a reason for hiding this comment

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

I assume that we expect ppl to call addA11y on the action resolver manually when using it on the dispatcher, right?

@tbondwilkinson
Copy link
Contributor Author

I assume that we expect ppl to call addA11y on the action resolver manually when using it on the dispatcher, right?

That's correct. Here's a code sample from a future CL that updates Wiz to use ActionResolver.

    const actionResolver =
        new ActionResolver({syntheticMouseEventSupport: true});
    actionResolver.addA11yClickSupport(
        a11yClick.updateEventInfoForA11yClick,
        a11yClick.preventDefaultForA11yClick,
        a11yClick.populateClickOnlyAction);

This isn't a great API! But it's temporary. Once we refactor to get everyone onto ActionResolver in Dispatcher, we no longer need the deferred support, and it can just become a boolean, like syntheticMouseEventSupport.

Copy link
Contributor

@dylhunn dylhunn left a comment

Choose a reason for hiding this comment

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

reviewed-for: public-api

@pullapprove pullapprove bot requested a review from alxhub May 13, 2024 23:39
@tbondwilkinson
Copy link
Contributor Author

Caretaker note: cl/633383853 must be patched into sync CL to update internal BUILD rules.

@tbondwilkinson tbondwilkinson added the merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note label May 14, 2024
@tbondwilkinson
Copy link
Contributor Author

@AndrewKushnir re-requested review for public-api

Copy link
Contributor

@AndrewKushnir AndrewKushnir left a comment

Choose a reason for hiding this comment

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

Reviewed-for: public-api

@tbondwilkinson tbondwilkinson added action: merge The PR is ready for merge by the caretaker action: review The PR is still awaiting reviews from at least one requested reviewer and removed action: review The PR is still awaiting reviews from at least one requested reviewer action: merge The PR is ready for merge by the caretaker labels May 14, 2024
@tbondwilkinson
Copy link
Contributor Author

This will cause a merge conflict with #55756 so I'll wait for that

@tbondwilkinson tbondwilkinson added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels May 14, 2024
This will enable internal usages to migrate from ActionResolver in
EventContrat to ActionResolver in Dispatcher.
@atscott
Copy link
Contributor

atscott commented May 14, 2024

This PR was merged into the repository by commit f1e3ec2.

@atscott atscott closed this in f1e3ec2 May 14, 2024
atscott pushed a commit that referenced this pull request May 14, 2024
This will enable internal usages to migrate from ActionResolver in
EventContrat to ActionResolver in Dispatcher.

PR Close #55757
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
action: merge The PR is ready for merge by the caretaker area: core Issues related to the framework runtime core: event dispatch merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note requires: TGP This PR requires a passing TGP before merging is allowed target: rc This PR is targeted for the next release-candidate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants