Skip to content

refactor(material/core): no longer define stateChanges in mixinErrorState #22875

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

Merged
merged 1 commit into from
Feb 17, 2022

Conversation

devversion
Copy link
Member

@devversion devversion commented Jun 3, 2021

The error state mixin provided in @angular/material/core currently
defines the stateChanges class member as part of the mixin. This
is unexpected as consumers might deal with the stateChanges member
differently. e.g. in some components the stateChanges field is
intended to show up in the docs, or the JSDoc descripton varies. e.g.
the observable could emit whenever form-field state changes, and it
should be updated, or it emits always when something changes (e.g.
even a component input which is not relevant for the form-field
control).

In general we want to avoid this member being defined in the mixin
as the mixin is rather about the error state, and not defining a
subject that can emit whenever "state" changes.

@devversion devversion added docs This issue is related to documentation target: patch This PR is targeted for the next patch release labels Jun 3, 2021
@devversion devversion requested review from crisbeto and mmalerba June 3, 2021 19:08
@devversion devversion requested a review from jelbourn as a code owner June 3, 2021 19:08
@google-cla google-cla bot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Jun 3, 2021
// The description is not specifically mentioning the error state, as classes using this
// mixin can/should emit an event in other cases too.
/** Emits whenever the component state changes. */
readonly stateChanges = new Subject<void>();
Copy link
Member Author

Choose a reason for hiding this comment

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

I've added the internal comment here because I was actually surprised about stateChanges being defined here. I've also wondered on whether it should be made docs-private or not. I'm unsure on whether we should move this out of the mixin (as a cleanup) and require the mixin base classes to define the stateChanges property, but it looks like this mixin is commonly used within form-fields.. I kept it public because there are other cases where we have stateChanges intentionally showing-up in the docs.

Copy link
Member

Choose a reason for hiding this comment

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

Now that you mention it, it does sound weird that this is initialized in the mixin. Maybe it should be moved to all the places that apply the mixin instead? The interface should enforce that it's always defined.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I agree, I was surprised too and left this comment to start the conversation.

Copy link
Member Author

Choose a reason for hiding this comment

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

@crisbeto I've went ahead and just made the changes as part of this PR.

Copy link
Member

@crisbeto crisbeto left a comment

Choose a reason for hiding this comment

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

LGTM on the docs changes.

// The description is not specifically mentioning the error state, as classes using this
// mixin can/should emit an event in other cases too.
/** Emits whenever the component state changes. */
readonly stateChanges = new Subject<void>();
Copy link
Member

Choose a reason for hiding this comment

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

Now that you mention it, it does sound weird that this is initialized in the mixin. Maybe it should be moved to all the places that apply the mixin instead? The interface should enforce that it's always defined.

@devversion devversion added the merge: preserve commits When the PR is merged, a rebase and merge should be performed label Jun 4, 2021
@devversion devversion requested a review from crisbeto June 4, 2021 13:31
@devversion devversion force-pushed the docs/mixin-error-state branch from 260fbbe to 47baa6d Compare June 4, 2021 13:50
Copy link
Member

@jelbourn jelbourn left a comment

Choose a reason for hiding this comment

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

lgtm

@jelbourn jelbourn added the action: merge The PR is ready for merge by the caretaker label Jun 7, 2021
@devversion devversion added needs: discussion Further discussion with the team is needed before proceeding and removed action: merge The PR is ready for merge by the caretaker merge: preserve commits When the PR is merged, a rebase and merge should be performed labels Jun 18, 2021
@devversion
Copy link
Member Author

I've extracted the first commit into a separate PR so that we can land the "docs fix" in a non-breaking way: #23010. This PR remains open for further discussion given it's technically a breaking change (although I doubt the risk is high here).

@devversion devversion force-pushed the docs/mixin-error-state branch from 47baa6d to 68cb7b5 Compare July 6, 2021 13:13
@devversion devversion changed the title docs: add missing documentation for error state properties refactor(material/core): no longer define stateChanges in mixinErrorState Jul 6, 2021
@devversion devversion added action: merge The PR is ready for merge by the caretaker target: major This PR is targeted for the next major release and removed target: patch This PR is targeted for the next patch release docs This issue is related to documentation labels Jul 6, 2021
@devversion devversion force-pushed the docs/mixin-error-state branch 2 times, most recently from f76ca5b to 79b3e09 Compare July 6, 2021 13:48
@devversion devversion force-pushed the docs/mixin-error-state branch from 79b3e09 to 8ebc46d Compare August 17, 2021 10:10
@devversion devversion requested a review from a team as a code owner August 17, 2021 10:10
@josephperrott josephperrott removed the request for review from a team August 17, 2021 17:33
@andrewseguin andrewseguin removed the cla: yes PR author has agreed to Google's Contributor License Agreement label Dec 28, 2021
@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Dec 29, 2021
@devversion devversion force-pushed the docs/mixin-error-state branch from 8ebc46d to 1a25f4c Compare January 31, 2022 13:39
…orState`

The error state mixin provided in `@angular/material/core` currently
defines the `stateChanges` class member as part of the mixin. This
is unexpected as consumers might deal with the `stateChanges` member
differently. e.g. in some components the `stateChanges` field is
intended to show up in the docs, or the JSDoc descripton varies. e.g.
the observable could emit whenever form-field state changes, and it
should be updated, or it emits always when something changes (e.g.
even a component input which is not relevant for the form-field
control).

In general we want to avoid this member being defined in the mixin
as the mixin is rather about the error state, and not defining a
subject that can emit whenever "state" changes.

BREAKING CHANGE: Previously the `mixinErrorState` mixin function defined
a class member for `stateChanges`. This is no longer the case, and consumers
need to provide the `stateChanges` class member themselves.
@devversion devversion force-pushed the docs/mixin-error-state branch from 1a25f4c to 310fcb6 Compare January 31, 2022 13:42
@devversion devversion removed needs: discussion Further discussion with the team is needed before proceeding needs rebase labels Jan 31, 2022
@devversion devversion added this to the 14.0.0 milestone Jan 31, 2022
@andrewseguin andrewseguin merged commit bab3b98 into angular:master Feb 17, 2022
@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 20, 2022
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 cla: yes PR author has agreed to Google's Contributor License Agreement target: major This PR is targeted for the next major release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants