@devcorp-libs/ng-unsubscribe

Base class for handling unsubscribe on destroy

Usage no npm install needed!

<script type="module">
  import devcorpLibsNgUnsubscribe from 'https://cdn.skypack.dev/@devcorp-libs/ng-unsubscribe';
</script>

README

NgUnsubscribe

Base class for handling unsubscribe on destroy

Usage

Just extend NgUnsubscribe class and use takeUntil(this.ngUnsubscribe) pipe on each observable

Example how to use it

@Component({
  ...
})
export class MyComponent extends NgUnsubscribe {

  public readonly sub$: Observable<any>;

  constructor() {
    super();
    
    this.sub$ = of({}).pipe(
      takeUntil(this.ngUnsubscribe),
    )        
  }
}