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

Add rule to enforce markForCheck on async updates #2

Open
ajafff opened this issue Jul 26, 2019 · 0 comments
Open

Add rule to enforce markForCheck on async updates #2

ajafff opened this issue Jul 26, 2019 · 0 comments

Comments

@ajafff
Copy link
Member

ajafff commented Jul 26, 2019

@Component({
  template: `
    <span (click)="onClicked()">{{loading}}</span>
  `,
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class SomeComponent {
  public ngOnInit() {
    setTimeout(() => this.loading = true, 1000); // needs markForCheck
  }
  public async onClicked() {
    this.loading = true; // fine
    await someAsyncStuff();
    this.loading = false; // needs markForCheck
  }
}

Only operates on Components with OnPush strategy. (TBD: what about directives? they could be used everywhere)

Needs to gather all properties used as property binding. Will probably not work for properties used in get accessors and methods.
A lambda that modifies component state needs to have markForCheck.
Async functions that modify the components state after await need markForCheck. Probably requires a control flow graph.

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

No branches or pull requests

1 participant