ngx-leave
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

:) 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

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

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

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 👽 😂😂

Package Sidebar

Install

npm i ngx-leave

Weekly Downloads

1

Version

2.0.0

License

MIT

Unpacked Size

14.4 kB

Total Files

18

Last publish

Collaborators

  • angodev