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): avoid direct references to the Validators
class
#41189
perf(forms): avoid direct references to the Validators
class
#41189
Conversation
Note: this PR is related to (and partially addresses) #41011. |
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!
Currently the `Validators` class contains a number of static methods that represent different validators as well as some helper methods. Since class methods are not tree-shakable, any reference to the `Validator` class retains all of its methods (even if you've used just one). This commit refactors the code to extract the logic into standalone functions and use these functions in the code instead of referencing them via `Validators` class. That should make the code more tree-shakable. The `Validators` class still retains its structure and calls these standalone methods internally to keep this change backwards-compatible.
04d293e
to
966d897
Compare
This has been merged into master only due to conflicts with 11.2.x. @AndrewKushnir can you create a patch-only PR for 11.2.x? |
…ar#41189) Currently the `Validators` class contains a number of static methods that represent different validators as well as some helper methods. Since class methods are not tree-shakable, any reference to the `Validator` class retains all of its methods (even if you've used just one). This commit refactors the code to extract the logic into standalone functions and use these functions in the code instead of referencing them via `Validators` class. That should make the code more tree-shakable. The `Validators` class still retains its structure and calls these standalone methods internally to keep this change backwards-compatible. PR Close angular#41189
I came across this whilst looking through the CHANGELOG and updating Angular Is this just an internal change or do users of I have quite a lot of code that looks something like this: public emailControl = new FormControl("", [Validators.email, Validators.required]); Does it need to be written in a different way to be tree-shakeable? |
@ockendenjo It's an internal only change for now, so your code is not affected (nor can it benefit from this change at the moment). Please see #41257 for details. |
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. |
Currently the
Validators
class contains a number of static methods that represent different validators as well as some helper methods. Since class methods are not tree-shakable, any reference to theValidator
class retains all of its methods (even if you've used just one).This commit refactors the code to extract the logic into standalone functions and use these functions in the code instead of referencing them via
Validators
class. That should make the code more tree-shakable. TheValidators
class still retains its structure and calls these standalone methods internally to keep this change backwards-compatible.PR Type
What kind of change does this PR introduce?
Does this PR introduce a breaking change?