# ngx-auto-unsubscribe-decorator

> Decorator for auto unsubscribtion from observable

Latest version **1.1.0** (published 2022-03-31) · MIT license · 0 weekly downloads

## Install

```sh
npm install ngx-auto-unsubscribe-decorator
pnpm add ngx-auto-unsubscribe-decorator
yarn add ngx-auto-unsubscribe-decorator
bun add ngx-auto-unsubscribe-decorator
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2022-03-31 |
| First published | 2021-10-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 23.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 28 |
| Author | Nillcon |
| Maintainers | nillcon |
| Keywords | Angular, RxJs, Auto unsubscribe, Auto-unsubscribe, Autounsubscribe, Unsubscribe, Subscription, Observable unsubscribe |

## Links

- npm: https://www.npmjs.com/package/ngx-auto-unsubscribe-decorator
- Repository: https://github.com/Nillcon248/auto-unsubscribe
- Homepage: https://github.com/Nillcon248/auto-unsubscribe#readme
- Issues: https://github.com/Nillcon248/auto-unsubscribe/issues
- npm.io page: https://npm.io/package/ngx-auto-unsubscribe-decorator

## Dependencies (1)

- [tslib](https://npm.io/package/tslib.md) ^2.1.0

## Recent versions

- 1.1.0 (latest) — 2022-03-31
- 0.1.0 — 2022-03-30
- 1.0.0 — 2022-01-13
- 0.0.11 — 2021-10-31
- 0.0.10 — 2021-10-27
- 0.0.9 — 2021-10-06
- 0.0.8 — 2021-10-06
- 0.0.7 — 2021-10-06
- 0.0.6 — 2021-10-06
- 0.0.5 — 2021-10-06
- 0.0.4 — 2021-10-06
- 0.0.3 — 2021-10-06
- 0.0.2 — 2021-10-06
- 0.0.1 — 2021-10-06

## README

## Angular - Auto unsubscribe decorator 🦄

[![npm](https://img.shields.io/npm/dt/ngx-auto-unsubscribe-decorator.svg)]()
[![npm](https://img.shields.io/npm/l/ngx-auto-unsubscribe-decorator.svg)]()
[![Build status](https://travis-ci.org/Nillcon248/ngx-base-state.svg?branch=master)](https://travis-ci.org/Nillcon248/ngx-auto-unsubscribe.svg?branch=master)

# Installation

`npm i ngx-auto-unsubscribe-decorator`

## Idea 💡

This library has been created for removing
useless code with manually unsubscribes,
for this one was created decorator that works
with all types of subscriptions, you can wrap
observable parameter, a method that returns observable or
a method that returns subscription and doesn't think
about memory leak.

## Examples 🧪

### Work with parameters

```js
export class UserComponent implements OnInit {
  @AutoUnsubscribe() // <-- Should be on the target parameter
  private userData$ = new BehaviorSubject(/* Some data */);

  public ngOnInit(): void {
    // After ngOnDestroy this subscription will unsubscribe
    this.userData$.subscribe();

    // You can override parameter, it will unsubscribe too
    this.userData$ = new Subject();
    this.userData$.subscribe();
  }
}
```

### Work with methods

```js
export class UserComponent implements OnInit {

  public ngOnInit(): void {
    this.getUserData$().subscribe();

    this.initUserDataSubscription();
  }

  @AutoUnsubscribe() // <-- Should be on the target method
  public getUserData$(): BehaviorSubject {
    return new BehaviorSubject(/* Some data */);
  }

  @AutoUnsubscribe() // <-- Should be on the target method
  public initUserDataSubscription(): BehaviorSubject {
    return new BehaviorSubject(/* Some data */).subscribe();
  }
}

```

## Demo

See the [Example 1](https://stackblitz.com/edit/angular-ivy-3xkfrv?file=src/app/unsubscribe-decorator/unsubscribe-decorator.component.ts) [Example 2](https://stackblitz.com/edit/angular-ivy-ujz6vk?devtoolsheight=33&file=src/app/autounsubscribe/autounsubscribe.component.ts) on Stackblitz

---
_Source: https://npm.io/package/ngx-auto-unsubscribe-decorator · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
