Quantcast
Channel: JavaScriptMVC Forum
Viewing all articles
Browse latest Browse all 3491

Re : After a fragment is added to the DOM, why updating an observable updates the DOM as well?

$
0
0
so the object returned by can.view() is a DocumentFragment object, which is just a plain vanilla DOM object (on the browser environment), and I am just using document.body.appendChild() to add it to the DOM, and again that method is a plain vanilla DOM method.  But the page will be updated even if I set the attr of the observable:


So it seems like it is either one of the two:

1) An observer is created to observes list, and on change, re-render the template, and go to the fragment, look at the parentNode, and then replace the fragment by the new content of the template result.

2) the can.view creates an observer object or function that observes list.  And it computes value using the Mustache template (like a can.compute()).  But another observer observes this template result.  When list changes, that first observer is invoked and alter the template result, and the second observer is then invoked, taking the new template result and look at the fragment's parentNode and replace the fragment with the new content.

Is the above more or less correct?  But maybe either way, we can just treat it as "magic", but take that when we get back a DocumentFragment and add it to our DOM, any change to the items that the template used that are observable will be reflected on the page at the fragment's location.



Viewing all articles
Browse latest Browse all 3491

Trending Articles