ngx-template-streams: Seems to be breaking my ngOnDestroy implementation in a class I'm extending from

So I have this class I extend most of my “smart” components from.

import {  OnInit, OnDestroy } from '@angular/core';
import { Store, Action } from '@ngrx/store';
import { Subject, merge, Observable } from 'rxjs';
import { takeUntil, filter } from 'rxjs/operators';

export const isOnInit = () => filter((l) => l === 'OnInit');
export const isOnDestroy = () => filter((l) => l === 'OnDestroy');

export class BaseClass implements OnInit, OnDestroy {
  lifecycle$ = new Subject<'OnInit' | 'OnDestroy'>();

  ngOnInit() {
    this.lifecycle$.next('OnInit');
  }

  ngOnDestroy() {
    this.lifecycle$.next('OnDestroy');
    this.lifecycle$.complete();
  }

  dispatchActions$$(store: Store<any>, actions: Observable<Action>[]) {
    merge(...actions)
      .pipe(takeUntil(this.lifecycle$.pipe(isOnDestroy())))
      .subscribe(store);
  }
}

as soon as @ObservableEvent() is used inside a class that extends from this class I don’t get the OnDestroy message from lifecycle$

@d3lm

About this issue

  • Original URL
  • State: open
  • Created 5 years ago
  • Comments: 18 (18 by maintainers)

Most upvoted comments

OK, thanks for opening the issue. I have indeed not tested class inheritance. I will try to debug this. AOT is indeed problematic here because in AOT it assumes the lifecycle to be there and my guess is that my TS transformer doesn’t properly work in the case of inheritance. I’ll have a look.