Managing Subscriptions in Angular
Christian Johns
1021

Hi,

What do you think of below?

import { OnDestroy } from '@angular/core';
import * as _ from 'lodash';
import { Subscription } from 'rxjs/Subscription';

export class SubscriptionManager implements OnDestroy {

private subscription: Subscription[] = [];

public ngOnDestroy(): void {
_.forEach(this.subscription, (subscription: Subscription) => {
subscription.unsubscribe();
}
);
}

protected addSubscription(subscription: Subscription): void {
this.subscription.push(subscription);
}
}

extends SubscriptionManager and push subscriptions to array.