Socket
Book a DemoInstallSign in
Socket

take-until-destroy

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

take-until-destroy

A simple way to unsubscribe from an RxJs stream in Angular (2+) when the component is destroyed

2.1.0
latest
Source
npmnpm
Version published
Maintainers
1
Created
Source

take-until-destroy

A simple way to unsubscribe from an RxJs stream in Angular (6.0+) when the component is destroyed

For an overview of how this works see this post about unsubscription in angular

Coverage Status Build Status Dependencies JavaScript Style Guide

Installation

npm install take-until-destroy --save || yarn add take-until-destroy

Use

 import { Destroyable, takeUntilDestroy } from 'take-until-destroy'
 
 // If you have already implemented `OnDestroy`, you don't need the `@Destroyable` decorator.
 @Destroyable
 @Component({
   ...
 })
 export class ExampleComponent {
    constructor(randomService: RandomService) {
        randomService.getObservable
            .pipe(takeUntilDestroy(this))
            .subscribe(v => {
                console.log(v)
            })
    }
 }

Known Issues

The @Destroyable decorator doesn't work in production. See https://github.com/jsdevtom/take-until-destroy/issues/7 for updates. The current fully working work around is to simply implement OnDestroy for you component and it will work as expected. Example:

 import { Destroyable, takeUntilDestroy } from 'take-until-destroy'
 
 @Component({
   ...
 })
 export class ExampleComponent implements OnDestroy {
    constructor(randomService: RandomService) {
        randomService.getObservable
            .pipe(takeUntilDestroy(this))
            .subscribe(v => {
                console.log(v)
            })
    }
    
    ngOnDestroy() {/**/}
 }

Keywords

angular

FAQs

Package last updated on 19 May 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.