ng-sub
Version:
Ng-Sub is a lightweight tool used to manage rxjs subscriptions and prevent memory leakage.
31 lines • 949 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.NgSub = void 0;
const rxjs_1 = require("rxjs");
class NgSub extends rxjs_1.Subject {
/**
* A class that extends Subject and provides a way to manage subscriptions.
* It allows adding multiple subscriptions and unsubscribing from all of them at once.
*/
constructor() {
super();
// Initialize the Subject and Subscription
// that will be used to manage the lifecycle of subscriptions.
this.d$ = new rxjs_1.Subject();
this.subscription = new rxjs_1.Subscription();
}
unsubscribe() {
this.d$.next();
this.d$.complete();
this.subscription.unsubscribe();
super.next();
super.complete();
}
add(...subs) {
subs.forEach(sub => {
this.subscription.add(sub);
});
}
}
exports.NgSub = NgSub;
//# sourceMappingURL=index.js.map