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
perf(forms): make built-in ControlValueAccessors more tree-shakable #41146
Conversation
9e00943
to
557aa6c
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.
An alternative approach would be for all built-in CVAs to extend an internal abstract class. Then you could check for a built-in CVA using instanceof
. I feel that this would be a more clean approach than a semi-hidden internal property.
557aa6c
to
075d210
Compare
Thanks for the review @petebacondarwin 👍 As we discussed, I've updated the code to check whether a given CVA is an instance of a class that directly extends |
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! 🍪
Really simple and huge size savings! Great work!
reviewed-for: public-api
reviewed-for: size-tracking
@@ -59,7 +59,7 @@ | |||
"master": { | |||
"uncompressed": { | |||
"runtime-es2015": 1485, | |||
"main-es2015": 168534, | |||
"main-es2015": 162346, |
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.
👏🏻
Also started a Global Presubmit to verify that there are no edge cases that might be affected. |
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 - one suggestion about the docs.
@@ -139,4 +148,4 @@ export interface ControlValueAccessor { | |||
* @publicApi | |||
*/ | |||
export const NG_VALUE_ACCESSOR = | |||
new InjectionToken<ReadonlyArray<ControlValueAccessor>>('NgValueAccessor'); | |||
new InjectionToken<ReadonlyArray<ControlValueAccessor>>('NgValueAccessor'); |
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.
😱
return BUILTIN_ACCESSORS.some(a => valueAccessor.constructor === a); | ||
// Check if a given value accessor is an instance of a class that directly extends | ||
// `BuiltInControlValueAccessor` one. | ||
return Object.getPrototypeOf(valueAccessor.constructor) === BuiltInControlValueAccessor; |
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.
🎉
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
This commit updates Forms code to avoid direct references to all built-in ControlValueAccessor classes, which
prevents their tree-shaking from production builds. Instead, a new static property is added to all built-in
ControlValueAccessors, which is checked when we need to identify whether a given ControlValueAccessors is a
built-in one.
This PR partially implements #41011.
PR Type
What kind of change does this PR introduce?
Does this PR introduce a breaking change?