-
-
Notifications
You must be signed in to change notification settings - Fork 22
Open
Labels
Description
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();
}
}
Allcharles, Abasz and antonyboom