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

fix(forms): more precise handling of onCollectionChange callbacks #39685

Closed

Conversation

AndrewKushnir
Copy link
Contributor

Form controls have internal API that allows subscribing to changes in a data collection (for FormGroups and
FormArrays), when a new control is added to a collection or existing one is removed. This internal API is used
inside FormGroupDirective to trigger DOM updates. The problem with the current API is that there is no way to
append a callback or remove a particular one (for ex. a callback that belongs to a directive that is being
removed). Instead, new onCollectionChange callback always resets existing one.

This commit updates the logic of onCollectionChange callback handling to provide an ability to add and remove
particular callbacks without loosing previous callbacks. It resolves some of the problems in case a FormGroup
instance is shared between different instances of Forms directives as well as allowing for better cleanup
mechanisms to be implemented in followup PRs.

PR Type

What kind of change does this PR introduce?

  • Bugfix

Does this PR introduce a breaking change?

  • Yes
  • No

Form controls have internal API that allows subscribing to changes in a data collection (for FormGroups and
FormArrays), when a new control is added to a collection or existing one is removed. This internal API is used
inside FormGroupDirective to trigger DOM updates. The problem with the current API is that there is no way to
append a callback or remove a particular one (for ex. a callback that belongs to a directive that is being
removed). Instead, new `onCollectionChange` callback always resets existing one.

This commit updates the logic of `onCollectionChange` callback handling to provide an ability to add and remove
particular callbacks without loosing previous callbacks. It resolves some of the problems in case a FormGroup
instance is shared between different instances of Forms directives as well as allowing for better cleanup
mechanisms to be implemented in followup PRs.
@AndrewKushnir AndrewKushnir added type: bug/fix state: WIP area: forms target: patch This PR is targeted for the next patch release labels Nov 14, 2020
@google-cla google-cla bot added the cla: yes label Nov 14, 2020
@ngbot ngbot bot modified the milestone: needsTriage Nov 14, 2020
@AndrewKushnir AndrewKushnir changed the title fix(forms): more precise handling of the onCollectionChange callbacks fix(forms): more precise handling of onCollectionChange callbacks Nov 14, 2020
@AndrewKushnir
Copy link
Contributor Author

Presubmit.

@AndrewKushnir
Copy link
Contributor Author

Quick update: it turned out that this change is quite break-y and we would not be able to land it in minor or patch versions (only in major). I'll need to do more investigation to figure out how that would affect #39235.

@AndrewKushnir
Copy link
Contributor Author

Closing this PR for now as it's not needed at this moment and improving onCollectionChange callback internal functionality breaks apps (so it should be landed as a breaking change).

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Mar 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant