2.0.0 • Published 5 years ago

ngx-leave v2.0.0

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

:) 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() {  }
}

Optiondescriptiondefault
subscriptionsarray all name of subscription[]
arrayNamename variable with subscription name''
methodfunction name to lib callngOnDestroy

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çãoDescrição
Test Suite4 passed, 4 total
Tests17 passed, 17 total
Snapshots0 total
Time6.129s
Ran all test suites

Obrigado / Thanks 👊 👊 ✊ ✌️

All Devs 👽 😂😂

2.0.0

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.3.15

5 years ago

0.3.14

5 years ago

0.3.13

5 years ago

0.3.11

5 years ago

0.3.10

5 years ago

0.3.12

5 years ago

0.3.9

5 years ago

0.3.8

5 years ago

0.3.7

5 years ago

0.3.5

5 years ago

0.3.4

5 years ago

0.3.2

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.0.1

5 years ago