This is more a question about best practices. When trying to apply an MVC pattern similar to a pattern in a web application, the question often arises as to how I need to update the view.
For example, if I have to update View_1, which has an X number of elements. Is it better:
A: iterate through each of the X elements, the calculation of which needs to be updated and the DOM change applied with very fine detail.
or
B: using the data provided by Model or some other data structure to restore the markup for all of this View and all its incoming elements and replace the root element of View_1 in the same DOM manipulation?
Correct me if I am wrong. I heard that rendering engines are usually more efficient at replacing most of the DOM at a time than a few smaller DOM operations. If so, then approach B is superior. However, even with the use of template mechanisms, it is still difficult for me to avoid overwriting labels for parts that are not changed.
I looked at the source code of the Bespin project before renaming it. I clearly remember that they implemented some kind of rendering cycle mechanism where DOM operations are queued and applied at fixed time intervals, similar to how games manage their frames. This is similar to approach A. I can also see the rationale for this approach. The small DOM operations used in this way support the user interface (especially important for a text editor). Also in this way, the application can be made more efficient only by updating the elements that need to be changed. Static text and aesthetic elements can remain intact.
These are my arguments for both sides. Guys, what do you think? Are we looking for a happy environment somewhere, or is one approach far superior?
Are there any good books / articles / sites on this topic?
(let it be assumed that the web application in question interacts strongly with many dynamic updates)
Viele source share