As we have more implementation in our ongoing project, more and more criteria we need to take care in our system. That includes business logic, flexibility of system, and system flow. Our topic is about managing system flow.
As what you should know, I am implementing function to getItemData() everytime I select an item in list. However, when I select an item, it trigger selected event that would call event1, which event1 would call selected event, forming an infinite loop. I then figure out some idea to handle this situation as I saw my supervisor’s existing code implementation.
To achieve my my implementation, I have to add a custom status checker to control the flow of system. Below are code for my status checker:private enum SelectedStatus
{
Normal,
Selected,
}private SelectedStatus _selectedStatus = SelectedStatus.Normal; //declare default value of SelectedStatus
public void SelectedEvent
{
if (_selectedStatus == SelectedStatus.Normal)
{
_selectedStatus = SelectedStatus.Selected;
_eventAggregator.GetEvent().Publish(id); //call event1 that cause loop
}
else
{
//logic//
_selectedStatus = SelectedStatus.Normal;
}
}
When Event1 callback to current function, _selectedStatus would now be SelectedStatus.Selected and will not publish another event to cause infinite loop. At the same time, I am able to get latest item data each time I select the data. My intention of getting latest item data is to ensure I can update data changes and minimize concurrency situation.
In future, if there is more features to add on, we can always add few more variable in SelectedStatus. This way, It provide more alternative for us to control/restrict our system flow.
