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

Support OnPush change detection for class-specified components (to allow use of knobs) #6360

Merged
merged 5 commits into from
Apr 2, 2019

Conversation

MaximSagan
Copy link
Contributor

Issue: #6359

What I did

In AppComponent,

  • I used the changed detector ref retrieved from the child component's injector (componentRef.injector.get(ChangeDetectorRef)), rather than the one available as a property on the component ref object (componentRef.changeDetectorRef), as the latter does not work.
  • After the properties are updated, I mark the child component for checking (childChangeDetectorRef.markForCheck()), but I call change detection from the AppComponent itself (this.changeDetectorRef.detectChanges()) to ensure that any properties using @HostBinding are also updated.

How to test

  • Is this testable with Jest or Chromatic screenshots?
    I don't think so, unless we there is an easy way to produce screenshots after knob interaction.
  • Does this need a new example in the kitchen sink apps?
    Yes, included in this PR.
  • Does this need an update to the documentation?
    No.

@kroeder
Copy link
Member

kroeder commented Apr 1, 2019

Thanks for that PR! Looks like you need to update the snapshots in order to get the CI tests passing 🙂 The easiest way is to run yarn test and select Update all snapshots

I'll give it a review afterwards

@MaximSagan
Copy link
Contributor Author

MaximSagan commented Apr 2, 2019

@kroeder

Thanks for that PR! Looks like you need to update the snapshots in order to get the CI tests passing 🙂 The easiest way is to run yarn test and select Update all snapshots

I'll give it a review afterwards

Sorry, missed that. Should be good now!

@vercel
Copy link

vercel bot commented Apr 2, 2019

This pull request is automatically deployed with Now.
To access deployments, click Details below or on the icon next to each push.

Latest deployment for this branch: https://monorepo-git-fork-maximsagan-angular-suppo.storybook.now.sh

Copy link
Member

@kroeder kroeder left a comment

Choose a reason for hiding this comment

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

LGTM

@electrovir
Copy link

I just spent hours trying to solve a problem similar to this and all I needed was your simple componentRef.injector.get(ChangeDetectorRef). Shame on Angular. Whatever, thank you so much!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants