There have been multiple instances where I encountered difficulties in implementing a more reactive approach, especially when trying to figure out how to make a method return an Observable in a clean manner.
Here is an example of the code snippet:
public updateItemEligibility(item: Item): void
{
this.updateCalculations(item);
if (item.status == Status.Full)
{
this.markEligibleItem(item);
}
if (item.quantity > 0 && item.Stage == 1)
{
const info: ItemInfo = this.getAdditionalInfoFromApi(); // will use observable
if (info.Staged)
{
this.updateStagedCalculations(item);
}
}
if (item.quantity == 0 && item.Stage == 2)
{
const stagingInfo: StagingInfo = this.getStaginInfoFromApi();
item.eligible = this.allowStagedItems && item.amount > 0 && stagingInfo.Stages[item.stage].Completed == true;
}
this.updateTotals(item);
}
One significant issue here is the necessity to call the API only when specific conditions are met.