user

Shilpa

28 Feb 2022

In Angular project, RxJS isStopped is deprecated! What is the alternative?

Angular

My visual code tslint and some other extensions are installed for my angular project. While reviewing my code, It shows isStopped is deprecated. what should I use instead of isStopped?

I want to rewrite my code with latest available methodology. Deprecated functions are causing showstopper to the application sometimes!

public createPatientChart(dataItemSet: any): any {
		this.showLoader = true;
 if (!this.sbscrbr.isStopped) {
 this.chart = this.healthService.createPatientBMIChart(dataItemSet, this.chartId, this.optionPool, this.extendedOptions);
 	 this.showLoader = false;

 return this.chart;
 }

	 this.showLoader = false;
 return null;
 
}

Any compatible code alternative for this code block?

Comments

Rakshit

1 Mar 2022

Best Answer

best answer

If you would like to check, whether your all subscribers (this.sbscrbr variable) are unsubscribed - In that case, RxJS introduced closed property. Here I rewrote the code for you,

 

public createPatientChart(dataItemSet: any): any {
		this.showLoader = true;
 if (!this.sbscrbr.closed) { //Use closed here to check your subscriber's state.
 this.chart = this.healthService.createPatientBMIChart(dataItemSet, this.chartId, this.optionPool, this.extendedOptions);
 	 this.showLoader = false;

 return this.chart;
 }

	 this.showLoader = false;
 return null;
 
}

closed will do the trick for you.

© 2024 Copyrights reserved for web-brackets.com