View Specific Observable Repositories #57
mlarandeau
started this conversation in
General
Replies: 1 comment
-
I 100% agree. I am guilty of adding an observable repository that is reused but not shared (new instance for each implementation across the app) in the interest of reusing logic but in hindsight this could be done just as well via shared VSM models instead. I would classify shared observable repositories as an "advanced" pattern considering the complexity of stitching together the repository events and the VSM state events + ensuring we aren't introducing any dangerous relationships in terms of reference objects. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
The VSM docs discuss the use of shared reusable repositories as the recommended means of communicating data and data changes between VSM views. And the sample code steps through this pattern when describing how to implement state models. I fully support this pattern and agree that this should be the recommended approach when needing to share data between views. However, I frequently see views introduce observable repositories that are specific to a that view (i.e. they are not shared).
Introducing an observable repository that is not shared between views can have negative impacts to the view:
So in the context of a view that does not need to share data with other views, I typically build the state models to perform any data loading directly, performs any transformations necessary on that data, and then pass that data onto the next state. Each consecutive state does the same by passing the data directly to the next state. In this scenario, there is no need to observe data changes since the current state is in control of all data changes. I find this ends up being easier to follow since clear connections between states are made and it keeps the state data more isolated. And in situations where there are data actions that need to be shared across different states, leaning on protocol-oriented programming as described here (or other similar protocol-oriented patterns) generally resolves the issue without introducing the complications outlined above.
So the questions I was hoping to discuss here are:
Beta Was this translation helpful? Give feedback.
All reactions