I have two instances of a view which are V1a and V1b. As they are instances of the same type they both use the same instance of the presentation model (PM1) as it is injected into each instance as a singleton. Each view shows different state (S1a for V1a and S1b for V1b) but switching between these two views (such as when they are in a TabNavigator) will give odd results:
- The user looks at V1a and sees the state in S1a;
- The user looks at V1b and sees the state for S1b;
- The user looks at V1a again but this time sees the state for S1b.
This is because S1b overwrites the state in the PM1 singleton so that when V1a is reopened, the view shows the state from V1b. I have three solutions:
- Don't inject singletons! but that seems to be the most common way of doing it;
- When the user switches the view it re-injects its data into PM1. This could get complicated in hierarchical views where the top level has the state and needs to inject it down to the bottom level. More care would need to be taken with bindings;
- Hold the state in the view and pass it to the PM when the view wants to act.
Solution 3 seems to be the simplest. However everything I have read about the presentation model tends to suggest that the state is held in the presentation model. Can anyone tell me where I am going wrong? As far as I can tell, it is far easier and safer to hold the state in the view than in the presentation model.