Managing Subscriptions in Angular
Christian Johns
211

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.

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.