Skip to content

refactor(mdc-prototypes): do not mark components dirty in input setters #16129

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

Conversation

devversion
Copy link
Member

@devversion devversion commented May 28, 2019

In order to make our component inputs which use boolean coercion more
consistent with other inputs which aren't declared through setters, we should
no longer call markForCheck within input setters as Angular automatically
runs change detection if input values are updated.

This breaks the programmatic usage of these inputs as Angular in that case
won't be able to run change detection (since it can't detect that the value
of the input changes).. though this is a more general problem with the
OnPush strategy as we can't have consistent behavior for programmatic
input updates without switching every input to a setter.

Instead, in order to still support programmatic input updates, we
could expose a method that allows developers to mark the MDC
components as dirty. This is necessary so that developers which
really need to update programmatically (e.g. through ViewChild)
can still update the componet to reflect the changes. The benefit is
that we don't need to convert every input to a setter w/ markForCheck
in order to make the OnPush inputs behavior consistent.

Related to COMP-170

Note: Removal of markForCheck as discussed in the last meeting and an additional proposal of adding a markForCheck method to components in order to still support programmatic input updates.

@devversion devversion added the target: patch This PR is targeted for the next patch release label May 28, 2019
@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label May 28, 2019
@devversion devversion added the needs: discussion Further discussion with the team is needed before proceeding label May 28, 2019
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, but there's a lint failure.

In order to make our component inputs which use boolean coercion more
consistent with other inputs which aren't declared through setters, we should
no longer call `markForCheck` within input setters as Angular automatically
runs change detection if input values are updated.

This breaks the programmatic usage of these inputs as Angular in that case
won't be able to run change detection (since it can't detect that the value
of the input changes).. though this is a more general problem with the
`OnPush` strategy as we can't have consistent behavior for programmatic
input updates without switching *every* input to a setter.

Instead, in order to still support programmatic input updates, we
should expose a method that allows developers to mark the MDC
components as dirty. This is necessary so that developers which
_really_ need to update programmatically (e.g. through `ViewChild`)
can still update the componet to reflect the changes. The benefit is
that we don't need to convert every input to a setter w/ markForCheck
in order to make the OnPush inputs behavior consistent.

Related to COMP-170
@devversion devversion force-pushed the refactor/mdc-prototypes-mark-for-check-input-setters branch from 202a9e3 to 1d4c09a Compare May 28, 2019 10:20
…t setters

Proposal to just not support programmatic input updates
@devversion devversion force-pushed the refactor/mdc-prototypes-mark-for-check-input-setters branch from f90baaa to c142748 Compare May 28, 2019 12:34
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

@devversion devversion added pr: lgtm action: merge The PR is ready for merge by the caretaker P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent and removed needs: discussion Further discussion with the team is needed before proceeding labels May 28, 2019
@jelbourn jelbourn merged commit 19af6ec into angular:master Jun 19, 2019
RudolfFrederiksen pushed a commit to RudolfFrederiksen/material2 that referenced this pull request Jun 21, 2019
…rs (angular#16129)

In order to make our component inputs which use boolean coercion more
consistent with other inputs which aren't declared through setters, we should
no longer call `markForCheck` within input setters as Angular automatically
runs change detection if input values are updated.

This breaks the programmatic usage of these inputs as Angular in that case
won't be able to run change detection (since it can't detect that the value
of the input changes).. though this is a more general problem with the
`OnPush` strategy as we can't have consistent behavior for programmatic
input updates without switching *every* input to a setter.

Instead, in order to still support programmatic input updates, we
should expose a method that allows developers to mark the MDC
components as dirty. This is necessary so that developers which
_really_ need to update programmatically (e.g. through `ViewChild`)
can still update the componet to reflect the changes. The benefit is
that we don't need to convert every input to a setter w/ markForCheck
in order to make the OnPush inputs behavior consistent.

Related to COMP-170
andrewseguin pushed a commit that referenced this pull request Jul 2, 2019
…rs (#16129)

In order to make our component inputs which use boolean coercion more
consistent with other inputs which aren't declared through setters, we should
no longer call `markForCheck` within input setters as Angular automatically
runs change detection if input values are updated.

This breaks the programmatic usage of these inputs as Angular in that case
won't be able to run change detection (since it can't detect that the value
of the input changes).. though this is a more general problem with the
`OnPush` strategy as we can't have consistent behavior for programmatic
input updates without switching *every* input to a setter.

Instead, in order to still support programmatic input updates, we
should expose a method that allows developers to mark the MDC
components as dirty. This is necessary so that developers which
_really_ need to update programmatically (e.g. through `ViewChild`)
can still update the componet to reflect the changes. The benefit is
that we don't need to convert every input to a setter w/ markForCheck
in order to make the OnPush inputs behavior consistent.

Related to COMP-170
@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 Sep 11, 2019
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 P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants