
Originally Posted by
Selkirk
Take a look at this sitepoint page. You can see that it has a hierarchical structure (all HTML does). Yet, not all of the branches of the hypothetical tree are rendered. Look at the tab at the top of the page. The articles, books, and blogs branches of the tree are not rendered as part of this page. The bulk of this page represents the forums branch in the greater application.
So the first stage is to take the input request and determine which portions of the tree to render. This is done by traversing the tree from the root to a leaf. This path from root to leaf is called the command path or the focus path.
The next stage is to build the composite view. For this, we walk the focus path from the leaf node back to the root. At each node we assimilate the view that is associated with that node. In addition, we can collect the children of the node that didn't receive focus, but that can participate in a composite view. These extra children are called 'active' children.
On this page, the articles, books, and blogs children are NOT active children. They can receive focus (When the user clicks on those tabs), but they do not participate in the composite view otherwise. You could imagine that it would be possible to have another organization of this page where those branches where simply hidden via the DOM and the tabs implemented by javascript. In that case, those branches would be considered 'active' because they would be rendered to the view.
As we move back up the line of focus, if we ever reach a point where our composite view cannot be a child of another view, then we stop and render it. This allows child trees to override layout set by a higher level node.
The reason we go from bottom to top when composing the views is purely for performance. Imagine that a lower level view overrode the master layout. It would have been a waste to instantiate the view object associated with the master layout too early. By traversing from the leaf to the root with our ViewComposer, we can be assured of instantiating only the view objects that we are going to actually be rendered. It does make building the composite view more difficult, however, this shouldn't matter to framework users.
Some nodes have children that can neither receive focus, nor activation. During the focus path building stage, events are able to forward focus to another part of the tree. When this happens, the focus path is re-drawn from the root to that node. Thus, nodes that can't receive focus based on direct user input can receive focus based on programmatic control. This is good for error messages, exceptional conditions, and wizards.
Sounds complicated, huh? My hope is that it won't be in actual practice. I'm still implementing it.
Bookmarks