iwstkhr / ngx-auto-destroy-deco

A class decorator for automatic unsubscription of rxjs observables

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ngx-auto-destroy-deco

Dependencies

  • Angular 13

Install

NOTE: Replace x.x.x with the version.

$ cd $YOUR_APP_PATH
$ curl -OL https://github.com/iwstkhr/ngx-auto-destroy-deco/raw/main/iwstkhr-ngx-auto-destroy-deco-x.x.x.tgz
$ npm add iwstkhr-ngx-auto-destroy-deco-x.x.x.tgz

Usage

Just add:

  1. @AutoDestroy decorator
  2. Class field used for takeUntil notifier
@Component({
  selector: 'app-sample',
  templateUrl: './sample.component.html',
})
@AutoDestroy()
export class SampleComponent implements OnInit {
  private readonly onDestroy$ = new Subject<void>();

  ngOnInit() {
    interval(1000).pipe(
      takeUntil(this.onDestroy$),
    );
  }
}

License

MIT

About

A class decorator for automatic unsubscription of rxjs observables

License:MIT License


Languages

Language:TypeScript 73.4%Language:JavaScript 26.6%