Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

753 B
Raw Blame
import { OnDestroyMixin, untilComponentDestroyed } from '@w11k/ngx-componentdestroyed';
import { Directive, OnDestroy } from '@angular/core';
import { Observable } from 'rxjs';

/**
 * Mixin function to provide access to observable and flags
 * whether this component has been destroyed.
 *
 * Use for rxjs with .pipe(this.untilDestroyed)
 */
@Directive()
export class UntilDestroyedMixin extends OnDestroyMixin implements OnDestroy {
  public componentDestroyed = false;

  ngOnDestroy():void {
    this.componentDestroyed = true;
    super.ngOnDestroy();
  }

  /**
   * Helper function to access `untilComponentDestroyed`
   */
  protected untilDestroyed<T>():(source:Observable<T>) => Observable<T> {
    return untilComponentDestroyed(this);
  }
}