For example, say I have two separate lists of items on a page. Perhaps we're ordering from a pizza and sub shop.
- List 1 - Food Type - Pizza, Sub
- List 2 - Condiment - Lettuce (Sub only), Onions (Both), Anchovies (Pizza only)
I have two separate reducers that track the selected items in list 1 and 2.
Say the user has Pizza and Anchovies selected, but decides he'd rather have a Sub. He switches his selection and an action is dispatched to update the foodType reducer. How does the condiment reducer become aware of this?
I see two possible solutions, but both are flawed.
I can listen to the FOOD_TYPE_CHANGED action in both reducers, and, assuming there's some additional computation necessary, also compute the new food type in the condiment reducer so the two don't need to be directly aware of each other. Of course this is redundant, but there's another issue with it as well. Let's say there's a third list that depends on the condiment selection. Do we now have to also listen to FOOD_TYPE_CHANGED and compute both foodType and condiment here? We can extend this concept out perpetually and it continues to get more complicated.
I can compose these into a single reducer and handle the interaction between the two at a higher level. But say I have a complex application with not just two, but ten pieces of interdependent state. This approach seems like it would get hairy very fast and not really serve to simplify anything as it scales.
Are there better ways to handle this type of situation?