# ngx-leave

> Decorador de classe que irá automaticamente cancelar os observáveis

Latest version **2.0.0** (published 2019-08-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install ngx-leave
pnpm add ngx-leave
yarn add ngx-leave
bun add ngx-leave
```

## 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 | 2.0.0 |
| Published | 2019-08-09 |
| First published | 2019-04-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 14.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | angodev |
| Keywords | Angular, ngx,  unsubscribe, Angular decorator unsubscribe, Angular unsubscribe observables |

## Links

- npm: https://www.npmjs.com/package/ngx-leave
- Repository: https://github.com/pedrstorm/autosub
- Homepage: https://github.com/pedrstorm/autosub#readme
- Issues: https://github.com/pedrstorm/autosub/issues
- npm.io page: https://npm.io/package/ngx-leave

## Alternatives

- [localforage](https://npm.io/package/localforage.md) — 6.2M weekly downloads
- [localforage-observable](https://npm.io/package/localforage-observable.md) — 30.8K weekly downloads
- [@y/y](https://npm.io/package/@y/y.md) — 30.1K weekly downloads
- [@metaobjectsdev/render](https://npm.io/package/@metaobjectsdev/render.md) — 3.5K weekly downloads
- [@ledgerhq/coin-algorand](https://npm.io/package/@ledgerhq/coin-algorand.md) — 1.1K weekly downloads

## Recent versions

- 2.0.0 (latest) — 2019-08-09
- 1.1.2 — 2019-04-12
- 1.1.1 — 2019-04-12
- 1.0.1 — 2019-04-12
- 1.0.0 — 2019-04-12
- 0.3.15 — 2019-04-12
- 0.3.14 — 2019-04-11
- 0.3.13 — 2019-04-11
- 0.3.11 — 2019-04-11
- 0.3.10 — 2019-04-11
- 0.3.12 — 2019-04-11
- 0.3.9 — 2019-04-11
- 0.3.8 — 2019-04-11
- 0.3.7 — 2019-04-11
- 0.3.5 — 2019-04-11
- … 5 more at https://npm.io/package/ngx-leave/versions

## README

# :) Unsubscribe para Pros and Juniors 💪 💨

### Problema


#### English 👳
When you subscribe to an observable or event in JavaScript, you needto unsubscribe to release memory in the system when you finish to use it. Otherwise, you will have a memory leak.

#### Português 😁
Quando você se inscrever em um evento observável ou em JavaScript, será necessário cancelar a assinatura da memória do sistema quando terminar de usá-lo. Caso contrário, você terá um vazamento de memória.



#### AutoLeave() 😁

## English.
Class decorator that will automatically unsubscribe from observable subscriptions when the component is destroyed .

## PT.
Decorador de classe que irá automaticamente cancelar os observáveis ​​quando o componente for destruído e não só  .



## Installation ⚡️

`npm install ngx-leave --save`


##AutoLeave

```js
import {AutoLeave} from "ngx-leave";

@AutoLeave({subscriptions: ['um$','tree$']})
@Component({
  selector: 'app'
})
export class appComponent  implements OnInit, OnDestroy{
  um$: Subscription;
  tree$: Subscription;

  constructor(  ) {  }

  ngOnInit() {

   this.um$ = from([0, 1, 2, 3, 4, 5, 6, 7]).subscribe(val => console.log(val));
   this.tree$ = from([0, 1, 2, 3, 4, 5, 6, 7]).subscribe(val => console.log(val));

  }


  // This method need to be implemented
  ngOnDestroy() {  }
}
```



###

| Option          | description                                            | default       |
| -----------     | ------------------------------------------------------ | ------------- |
| `subscriptions` |  array all name of subscription                        | `[]`          |
| `arrayName`     |  name variable with subscription name                  | `''`          |
| `method`        |  function name to lib call                             | `ngOnDestroy` |

Nota: `subscriptions` will be ignore if you set a value on `arrayName`.

`@AutoLeave({subscriptions: ['um$','tree$']})`

## Leave

```ts
import {Leave} from 'ngx-leave';

@Component({
  selector: 'app-test',
  templateUrl: './test.component.html',
})
export class testComponent implements OnInit, OnDestroy {

constructor(  ) {  }

ngOnInit() {
    interval(1000)
      .pipe(Leave(this))
      .subscribe(val => console.log(val));
  }


// This method need to be implemented
ngOnDestroy() {  }

}
```

### Option

Leave(this,functionName);

### Usando em uma class

```ts
import {Leave} from 'ngx-leave';

export class Widget {
  constructor() {
    interval(1000)
      .pipe(Leave(this, 'deleteFunc'))
      .subscribe(console.log);
  }

  // need to be created
  deleteFunc() {}
}
```


We test  💕 💞

| Ação        | Descrição
| ----------- | ------------------ |
| `Test Suite`| 4 passed, 4 total  |
| `Tests`     | 17 passed, 17 total  |
| `Snapshots` | 0 total            |
| `Time`      | 6.129s             |
| `Ran all test suites`            |




### Obrigado / Thanks  👊 👊 ✊ ✌️
All Devs  👽 😂😂

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