Looking for a way to improve the performance of the logic used for iterating over tree data and applying 'dataState' to 'FAILED' if there are matching error ids.
interface IData {
id: string;
label: string; .
value: string;
expanded: boolean;
condition?: boolean;
dataState: 'SUCCESS';
locked: boolean;
enabled: boolean;
parent: string;
children: IData[];
}
interface IErrors {
id: string;
success: boolean;
errors: Array<IError>;
}
The current logic is taking 2 seconds to execute and can be optimized for better performance. Here's the existing implementation:
public setFailedDataToStatusFailed(data:IData[],errorsList:IErrors[]){
data.forEach(data => {
errorsList.forEach(error => {
if(data){
if(data.id === error.id){
data.ruleState = 'FAILURE';
return;
} else if(data.children){
this.setFailedRulesToStatusFailed(data.children,errorsList);
}
}
});
});
}
If you have any suggestions on how to make this logic more efficient, please share. Thank you!