perf(forms): avoid direct references to the Validators class#41189
perf(forms): avoid direct references to the Validators class#41189AndrewKushnir wants to merge 1 commit intoangular:masterfrom
Validators class#41189Conversation
|
Note: this PR is related to (and partially addresses) #41011. |
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
Validatorsclass 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 theValidatorclass 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
Validatorsclass. That should make the code more tree-shakable. TheValidatorsclass 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?