@code-workers.io/ngx-destroy
TypeScript icon, indicating that this package has built-in type declarations

13.3.0 • Public • Published

@code-workers.io/ngx-destroy

Utility service to manage subscriptions in a declarative way using takeUntil.

To handle subscriptions in a declarative way usually you do have following code:

import { OnDestroy } from '@angular/core';
import { interval, Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators'
@Component({
  //...
})
export class SomeComponent implements OnDestroy {
  private readonly destroy$ = new Subject();

  constructor() {
    interval(1000)
      .pipe(takeUntil(this.destroy$))
      .subscribe(// do smth.)
  }
  
  ngOnDestroy() {
    this.destroy$.next();
    this.destroy$.complete();
  }
}

With NgxDestroy you reduce a lot of boilerplate:

import { interval } from 'rxjs';
import { NgxDestroy } from '@mikelgo/ngx-destroy';

@Component({
  //...
  providers: [NgxDestroy]
})
export class SomeComponent {
  
  constructor(private readonly destroy$: NgxDestroy) {
    interval(1000)
      .pipe(takeUntil(this.destroy$))
      .subscribe(// do smth.)
  }
  
}

Installation

npm i @code-workers.io/ngx-destroy

Demo

A demo can be found here

Compatibility

  • ngx-destroy 13.3.0 is compatible with Angular >= 13.3.0

Readme

Keywords

none

Package Sidebar

Install

npm i @code-workers.io/ngx-destroy

Weekly Downloads

2

Version

13.3.0

License

none

Unpacked Size

12 kB

Total Files

12

Last publish

Collaborators

  • mikelgo