I am currently developing a simple editor as part of the learning process. Its basic hierarchical tree-like structure of polygon-line-point, which is implemented in the data model. I need to display this data in two views
First view: hierarchical data in a tree element Second view: visualized geometry on the screen
Following the MVVM pattern, I applied the model representation classes around the data model (the model point view, the linear model view, etc.). In the tree view, I use hierarchical data patterns to correctly display specific data. In the second view, I need to display the current state of the geometry, currently it’s just one shell of the view model around the polygon data class, which moves all the children and displays them in the onRender method. In this case, I use several presentation models using the same data as for completely different purposes.
There is a problem when I make some changes to the tree view model (for example, adding points), which leads to a change in the underlying data model. However, the second view model does not directly observe the data in the model view, it only updates the visualization if I make a modification through my models. Is there an elegant solution for updating both models at the same time?
source
share