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

Investigate more tree-shaking-friendly approach for @angular/forms utils #39640

Open
AndrewKushnir opened this issue Nov 12, 2020 · 2 comments
Open
Assignees
Labels
area: forms cross-cutting: tree-shaking feature: in backlog Feature request for which voting has completed and is now in the backlog feature Issue that requests a new feature
Milestone

Comments

@AndrewKushnir
Copy link
Contributor

AndrewKushnir commented Nov 12, 2020

Important note: this ticket just describes possible ideas on how to make Forms code more tree-shakable. There are no specific actions planned/needed at this point.

Currently a lot of logic in Forms is stored in classes (such as AbstractControl, FormControl, FormGroup, FormArray, Validators, etc). The code in these classes is not tree-shakable by Terser. Closure can tree-shake unused class methods, but it requires advanced optimization mode turned on (which may or may not be enabled for different apps for various reasons).

There are some PRs that add more logic (util methods) into AbstractControl-based classes (see #27222, #34210 and also related issues #27171, #34186). Adding more methods into AbstractControl-based classes would lead to additional payload size even if applications do not use them. It'd be great to have a way to add this kind of helpers/utils in a tree-shakable way (otherwise we won't be able to include them into the Forms code).

One possible solution to consider is creating standalone functions that would take the necessary controls as arguments are perform some actions inside, for example with the moveControl function (from #27222) that might look like:

// Proposed in PR #27222:
const formArray = new FormArray(...);
formArray.moveControl(/* from */ 2, /* to */ 5);

// Possible tree-shaking-friendly scenario:
import {moveControl} from '@angular/forms';

const formArray = new FormArray(...);
moveControl(formArray, /* from */ 2, /* to */ 5);

Note: there is a lot of consideration that should be taken into account (such as backwards-compatibility, DX, API consistency and ergonomics, etc) before creating any helper methods and more research/discussion is needed (when this work is prioritized).

@angular-robot
Copy link
Contributor

angular-robot bot commented Jun 4, 2021

Just a heads up that we kicked off a community voting process for your feature request. There are 20 days until the voting process ends.

Find more details about Angular's feature request process in our documentation.

@AndrewKushnir AndrewKushnir added feature: in backlog Feature request for which voting has completed and is now in the backlog and removed feature: votes required Feature request which is currently still in the voting phase labels Jun 5, 2021
@dylhunn
Copy link
Contributor

dylhunn commented Jul 14, 2021

This is blocking consideration of issues such as #27171.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: forms cross-cutting: tree-shaking feature: in backlog Feature request for which voting has completed and is now in the backlog feature Issue that requests a new feature
Projects
No open projects
Feature Requests
Proposed Projects
Development

No branches or pull requests

4 participants