0.0.8 • Published 2 years ago

@ng-clown/subs v0.0.8

Weekly downloads
-
License
-
Repository
-
Last release
2 years ago

Subs

An angular library to manage subscriptions to make our code much cleaner.

Installation

To install this package, just run the following command in the root directory of your angular project.

npm i @ng-clown/subs

How to use

To use this service, just inject subs to your component constructor.

import { Subs } from '@ng-clown/subs';
@Component({ ...  })
export class AppComponent {
    constructor(private subs: Subs) {}
}

After injecting the service we need to keep track of the observables by adding it to subs service instance using the add() method.

Adding observables to subs service

import { Subs } from '@ng-clown/subs';
@Component({ ...  })
export class AppComponent {

    sampleObservable$: Observable<any> = ...

    constructor(private subs: Subs) {
      this.subs.add(this.sampleObservable$);
    }
}

Now we don't have to worry about the all the subscriptions form sampleObservable$ as long as we call the unsubscribeAll() method of subs service when component is destroyed.

Unsubscribe all subscriptions

import { Subs } from '@ng-clown/subs';
@Component({ ...  })
export class AppComponent {

    sampleObservable$: Observable<any> = ...

    constructor(private subs: Subs) {
      this.subs.add(this.sampleObservable$);
    }

    ngOnDestroy() {
        this.subs.unsubscribeAll();
    }
}
0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago