Skip to content

Seems to be breaking my ngOnDestroy implementation in a class I'm extending from #8

Description

@fxck

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

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

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions