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
refactor(core): Add an ActionResolver option to Dispatcher. #55757
Conversation
df38cbe
to
372668e
Compare
TESTED=TGP |
DIFFBASE=#55721 |
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.
LGTM, just left a couple minor (non-blocking) comments.
if (this.useActionResolver) { | ||
this.actionResolver = new ActionResolver({ |
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.
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.
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.
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.
if (this.useActionResolver) { | ||
this.actionResolver!.resolve(eventInfo); | ||
} |
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.
nit:
if (this.useActionResolver) { | |
this.actionResolver!.resolve(eventInfo); | |
} | |
this.actionResolver?.resolve(eventInfo); |
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.
Likewise, this is specifically for DCR - the boolean allows JSCompiler to appropriately inline the value as constant and then remove the code.
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.
LGTM
Reviewed-for: public-api
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.
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 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 |
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.
reviewed-for: public-api
372668e
to
076ac6c
Compare
Caretaker note: cl/633383853 must be patched into sync CL to update internal BUILD rules. |
@AndrewKushnir re-requested review for public-api |
076ac6c
to
d3e2b01
Compare
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.
Reviewed-for: public-api
This will cause a merge conflict with #55756 so I'll wait for that |
d3e2b01
to
5600ce7
Compare
This will enable internal usages to migrate from ActionResolver in EventContrat to ActionResolver in Dispatcher.
5600ce7
to
e00fd86
Compare
This PR was merged into the repository by commit f1e3ec2. |
This will enable internal usages to migrate from ActionResolver in EventContrat to ActionResolver in Dispatcher. PR Close #55757
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?