Skip to content

Add rule to enforce markForCheck on async updates #2

Description

@ajafff
@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.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions