Socket
Socket
Sign inDemoInstall

ngx-auto-unsubscribe

Package Overview
Dependencies
0
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    ngx-auto-unsubscribe

Class decorator that automatically unsubscribes from observables and events


Version published
Weekly downloads
6.1K
increased by21.67%
Maintainers
1
Install size
14.8 kB
Created
Weekly downloads
 

Readme

Source

Angular - Auto Unsubscribe For Pros

npm Build Status Build Status npm Awesome

Class decorator that will automatically unsubscribe from observable subscriptions when the component is destroyed

Installation

npm install ngx-auto-unsubscribe --save

Usage

import { AutoUnsubscribe } from "ngx-auto-unsubscribe";

@AutoUnsubscribe()
@Component({
  selector: 'inbox'
})
export class InboxComponent {
  one: Subscription;
  two: Subscription;

  constructor( private store: Store<any>, private element : ElementRef ) {}

  ngOnInit() {
    this.one = store.select("data").subscribe(data => // do something);
    this.two = Observable.interval.subscribe(data => // do something);
  }

  // This method must be present, even if empty.
  ngOnDestroy() {
    // We'll throw an error if it doesn't
  }
}

Options

OptionDescriptionDefault Value
arrayNameunsubscribe from subscriptions only in specified array''
blackListan array of properties to exclude[]
eventa name of event callback to execute onngOnDestroy

Note: blackList is ignored if arrayName is specified.

Similar projects

You can also use https://github.com/NetanelBasal/ngx-take-until-destroy.

Keywords

FAQs

Last updated on 14 Jul 2019

Did you know?

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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc