rxjs-tslint-rules icon indicating copy to clipboard operation
rxjs-tslint-rules copied to clipboard

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

Open CosmoRing opened this issue 5 years ago • 3 comments

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();
  }
}

CosmoRing avatar Jan 21 '20 09:01 CosmoRing

I imagine this would be possible, but complicated and I can't see myself having the time to do this anytime soon.

cartant avatar Jan 26 '20 06:01 cartant

Is there any chance you add this enhancement soon?

antonyboom avatar Mar 16 '20 14:03 antonyboom

Is there any chance you add this enhancement soon?

No. It's simply not a priority for me.

cartant avatar Mar 16 '20 20:03 cartant