take-until-destroyed
TypeScript icon, indicating that this package has built-in type declarations

0.0.1-RC0 • Public • Published

@ngx-ext/take-until-destroyed

With this RxJS operator you can forget about unsubscribing manually.

Install

npm install @ngx-ext/take-until-destroyed

Use

import { OnInit, OnDestroy } from '@angular/core';
import { fromEvent } from 'rxjs';
import { takeUntilDestroyed } from '@ngx-ext/take-until-destroyed';

export class Example implements OnInit, OnDestroy {
  public ngOnInit(): void {
    // for example listen to click events  
    fromEvent(document, 'click')
      .pipe(
        takeUntilDestroyed(this),
      ).subscribe(() => console.log('clicked!'));
    // that's all, subscription will be removed along with class' instance destroy
  }

  public ngOnDestroy(): void {
    // error will be thrown if this method doesn't exist
    // can be empty but has to exist
  }
}

Readme

Keywords

none

Package Sidebar

Install

npm i take-until-destroyed

Weekly Downloads

1

Version

0.0.1-RC0

License

none

Unpacked Size

18.6 kB

Total Files

15

Last publish

Collaborators

  • danielkucal