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

feat(forms): add emitEvent option for AbstractControl-based class methods #31031

Closed

Conversation

MikeJerred
Copy link
Contributor

This commit adds an optional argument to the methods addControl
and removeControl in the FormGroup class. This argument can be
used to prevent an event from being emitted.

PR Close #29662

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • angular.io application / infrastructure changes
  • Other... Please describe:

What is the current behavior?

Issue Number: #29662

What is the new behavior?

An argument can now be specified to prevent an event from being emitted.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

@MikeJerred MikeJerred requested review from a team as code owners June 13, 2019 12:06
@MikeJerred
Copy link
Contributor Author

MikeJerred commented Jun 13, 2019

I don't know why the build is failing, it was working in PR #29664 which had exactly the same code changes

@ngbot ngbot bot added this to the needsTriage milestone Jun 14, 2019
@AndrewKushnir AndrewKushnir added the forms: Controls API Issues related to AbstractControl, FormControl, FormGroup, FormArray. label May 8, 2020
@pullapprove pullapprove bot requested a review from AndrewKushnir May 8, 2020 23:55
@JulianFarhi
Copy link

Do we have some news about PR review?

@AndrewKushnir AndrewKushnir added action: review The PR is still awaiting reviews from at least one requested reviewer feature Issue that requests a new feature target: minor This PR is targeted for the next minor release labels Feb 1, 2021
@ngbot ngbot bot modified the milestones: needsTriage, Backlog Feb 1, 2021
@AndrewKushnir
Copy link
Contributor

Hi @MikeJerred, sorry we didn't have a chance to review/reply earlier.

As I mentioned in #20439 (comment), we'd like to consider adding emitEvent config to the FormGroup and FormArray classes. This PR covers most of the functions already (except the FormGroup.setControl one) and has good test coverage, so I'm wondering if you might be interested in rebasing this PR and adding the emitEvent support to the FormGroup.setControl method as well? If you don't have time to look into that now, I can help with rebasing and extending FormGroup.setControl API.

Thank you.

@MikeJerred
Copy link
Contributor Author

@AndrewKushnir I have rebased this PR and added the changes to FormGroup.setControl. The tests are failing but as far as I can tell the failure is not related to my changes - perhaps you could help with debugging that?

@AndrewKushnir
Copy link
Contributor

Hi @MikeJerred, thanks for updating the PR!

The CI failure was a flake, restarting that CI job resolved the issue.

I will review the changes within the next couple days and get back with comments/feedback.

Thank you.

Copy link
Contributor

@AndrewKushnir AndrewKushnir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MikeJerred thanks for updating the PR! The changes look good, I've just left a few comments related to docs and tests. Please let me know if you have any questions and/or need any help. Thank you.

packages/forms/src/model.ts Outdated Show resolved Hide resolved
packages/forms/test/form_array_spec.ts Outdated Show resolved Hide resolved
packages/forms/test/form_array_spec.ts Outdated Show resolved Hide resolved
packages/forms/test/form_array_spec.ts Outdated Show resolved Hide resolved
packages/forms/test/form_array_spec.ts Outdated Show resolved Hide resolved
packages/forms/test/form_group_spec.ts Show resolved Hide resolved
packages/forms/test/form_group_spec.ts Outdated Show resolved Hide resolved
@MikeJerred MikeJerred requested review from AndrewKushnir and removed request for a team February 2, 2021 12:01
Copy link
Contributor

@AndrewKushnir AndrewKushnir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for additional changes @MikeJerred 👍

I've left a few more comments mostly around docs to rephrase them a bit to be aligned with the function itself.

Just as a thought for a future refactoring (later in a separate PR), it'd be great to make description of the opts argument more generic (do not name the action specifically, but just refer to it as the "current action"), so that it's easier to maintain. The docs may look like:

   * @param opts Allows to specify whether events should be emitted once the current 
   * operation is completed.
   * * `emitEvent`: When true or not supplied (the default), both `statusChanges` and 
   * `valueChanges` events are emitted with the latest status and value. When false, no 
   * events are emitted.

We'd probably need to revisit exiting functions as well and update opts argument docs in a similar way. But this is definitely outside of the scope of this PR (I'll create a ticket once this PR lands).

Thank you.

packages/forms/src/model.ts Outdated Show resolved Hide resolved
packages/forms/src/model.ts Outdated Show resolved Hide resolved
packages/forms/src/model.ts Outdated Show resolved Hide resolved
packages/forms/src/model.ts Outdated Show resolved Hide resolved
packages/forms/src/model.ts Outdated Show resolved Hide resolved
packages/forms/test/form_group_spec.ts Outdated Show resolved Hide resolved
packages/forms/test/form_group_spec.ts Show resolved Hide resolved
packages/forms/test/form_group_spec.ts Show resolved Hide resolved
packages/forms/test/form_group_spec.ts Outdated Show resolved Hide resolved
packages/forms/test/form_group_spec.ts Outdated Show resolved Hide resolved
@AndrewKushnir
Copy link
Contributor

AndrewKushnir commented Feb 11, 2021

@MikeJerred thanks for applying the changes.

I noticed that you've changed the implementation for options from using default value to making the second argument optional. I think these options are close, but the default value approach is more consistent with existing APIs. Could you please update it?

Also I want to share the next steps:

  • since this PR changes public API surface, more people from the public-api group would review the PR and provide feedback
  • address the feedback from reviewers
  • run tests in Google's codebase to make sure there are no breakages (we'll take care of that)
  • add "BREAKING CHANGES" section to the commit message and describe that custom classes that extend AbstractControl-based ones and override existing methods might need some updates

Thank you.

Copy link
Member

@petebacondarwin petebacondarwin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great. Thanks @MikeJerred

Copy link
Member

@petebacondarwin petebacondarwin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed-for: public-api

@AndrewKushnir AndrewKushnir removed action: review The PR is still awaiting reviews from at least one requested reviewer state: blocked labels Feb 12, 2021
@AndrewKushnir
Copy link
Contributor

AndrewKushnir commented Feb 12, 2021

Presubmit #2 + Global Presubmit #2 (internal-only links).

@AndrewKushnir
Copy link
Contributor

@MikeJerred quick update: tests in Google's codebase went well (after minor updates to classes that extend FormGroup and FormArray). We are very close to merging this change and the last step would be to squash all commits into one and add the "BREAKING CHANGE" note to the commit body, so the commit message may look like this:

feat(forms): add `emitEvent` option for AbstractControl-based class methods

This commit adds the `emitEvent` option to the following FromArray and FormGroup methods:

* FormGroup.addControl
* FormGroup.removeControl
* FormGroup.setControl
* FormArray.push
* FormArray.insert
* FormArray.removeAt
* FormArray.setControl
* FormArray.clear

This option can be used to prevent an event from being emitted when adding or removing controls.

BREAKING CHANGE:

The `emitEvent` option was added to the following `FromArray` and `FormGroup` methods:

* FormGroup.addControl
* FormGroup.removeControl
* FormGroup.setControl
* FormArray.push
* FormArray.insert
* FormArray.removeAt
* FormArray.setControl
* FormArray.clear

If your app has custom classes that extend `FromArray` or `FormGroup` classes and override the 
above-mentioned methods, you may need to update your implementation to take new options into
account and make sure that overrides are compatible from types perspective.

Closes #29662.

Please let us know once it's ready, we'll do final checks and add this PR to the merge queue.

Thank you.

@MikeJerred MikeJerred force-pushed the form-add-remove-control-options branch from 473821f to fa419d8 Compare February 13, 2021 10:24
@MikeJerred
Copy link
Contributor Author

@AndrewKushnir I have squashed the commits into one and adjusted the message.

@rafaelss95
Copy link
Contributor

@MikeJerred there are some typos in your commit: FromArray should be FormArray.

…ethods

This commit adds the `emitEvent` option to the following FormArray and FormGroup methods:

* FormGroup.addControl
* FormGroup.removeControl
* FormGroup.setControl
* FormArray.push
* FormArray.insert
* FormArray.removeAt
* FormArray.setControl
* FormArray.clear

This option can be used to prevent an event from being emitted when adding or removing controls.

BREAKING CHANGE:

The `emitEvent` option was added to the following `FormArray` and `FormGroup` methods:

* FormGroup.addControl
* FormGroup.removeControl
* FormGroup.setControl
* FormArray.push
* FormArray.insert
* FormArray.removeAt
* FormArray.setControl
* FormArray.clear

If your app has custom classes that extend `FormArray` or `FormGroup` classes and override the 
above-mentioned methods, you may need to update your implementation to take the new options into
account and make sure that overrides are compatible from a types perspective.

Closes angular#29662.
@MikeJerred MikeJerred force-pushed the form-add-remove-control-options branch from fa419d8 to 960c354 Compare February 13, 2021 21:48
@AndrewKushnir
Copy link
Contributor

FYI, started a new presubmit in Google's codebase (internal-only link) to verify that there there are no places that might be broken by this change. Will keep this thread updated.

@AndrewKushnir AndrewKushnir added action: merge The PR is ready for merge by the caretaker and removed action: presubmit The PR is in need of a google3 presubmit labels Feb 16, 2021
@AndrewKushnir
Copy link
Contributor

FYI all affected tests in Google's codebase are successful, so I'm adding this PR to the merge queue.

@MikeJerred thanks for working on this PR and addressing the feedback! The change will be merged into the master branch and should be available as a part of the next major release (v12) in a few weeks.

@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 19, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker area: forms breaking changes cla: yes feature Issue that requests a new feature forms: Controls API Issues related to AbstractControl, FormControl, FormGroup, FormArray. target: major This PR is targeted for the next major release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot call FormGroup removeControl method without emitting an event
10 participants