There are many ways to handle multiple subscriptions efficiently in a component, I have 2 ways here and wanted to know which is more efficient and why??
Method 1: Using Array
Step 1: creating Array
private subscriptionArray: Subscription[];
Step 2: Adding subscriptions to the array
this.subscriptionArray.push(this._storeManagementHttp.createStore(newStore).subscribe(resp => {
this._toast.success('New store created');
}));
Step 3: iterating each subscription and unsubscribing
this.subscriptionArray.forEach(subs => subs.unsubscribe());
Method 2
Step 1: creating a new subscription
private subscriptions = new Subscription();
Step 2: Adding subscriptions
this.subscriptions.add(this._storeManagementHttp.createStore(newStore).subscribe(resp => {
this._toast.success('New store created');
this._router.navigate(['/store-management']);
}));
Step3: Clearing subscription
this.subscriptions.unsubscribe();