Skip to content

Support for class inheritance on rxjs-prefer-angular-takeuntil #113

@CosmoRing

Description

@CosmoRing

It's possible to add support for class inheritance on the rxjs-prefer-angular-takeuntil rule?
In the current projects i work on, all the common logic of a component is added on a BaseComponent where the subject is defined and called on the ngOnDestroy method. This method may our may not be overrided on the extended component.

An example of the most simple example is visible bellow.

export abstract class BaseComponent implements OnDestroy {
  public destroy: Subject<void> = new Subject();

  ngOnDestroy() {
    this.destroy.next(true);
    this.destroy.complete();
  }
}

@Component({
  selector: "correct-component"
})
class CorrectComponent extends BaseComponent implements OnDestroy {
  someMethod() {
    a.pipe(
      switchMap(_ => b),
      takeUntil(this.destroy)	
    ).subscribe();
  }

  ngOnDestroy() {
    super.ngOnDestroy();
  }

This same BaseCompoment may also be extended to another abstract component for more specific logic; example bellow.

export abstract class BaseComponent implements OnDestroy {
  public destroy: Subject<void> = new Subject();

  ngOnDestroy() {
    this.destroy.next(true);
    this.destroy.complete();
  }
}

export abstract class BaseFormComponent extends BaseComponent implements OnDestroy {
  
  (....generic form logic....)
  
  public ngOnDestroy() {
    super.ngOnDestroy();
	
	(....generic form logic....)
  }
}


@Component({
  selector: "correct-form-component"
})
class CorrectFormComponent extends BaseFormComponent implements OnDestroy {
  someMethod() {
    a.pipe(
      switchMap(_ => b),
      takeUntil(this.destroy)	
    ).subscribe();
  }

  ngOnDestroy() {
    super.ngOnDestroy();
  }
}

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions