Doc(LightDom): add some inline doc

This commit is contained in:
Victor Berchet 2015-01-24 13:33:58 +01:00
parent c797a4fbd5
commit 814f3d01ef
2 changed files with 18 additions and 6 deletions

View File

@ -9,7 +9,7 @@ import {NgElement} from 'core/dom/element';
var _scriptTemplate = DOM.createScriptTag('type', 'ng/content')
class ContentStrategy {
nodes;
nodes: List<Node>;
insert(nodes:List<Nodes>){}
}
@ -21,19 +21,21 @@ class ContentStrategy {
class RenderedContent extends ContentStrategy {
beginScript:Element;
endScript:Element;
nodes:List<Node>;
constructor(el:Element) {
this._replaceContentElementWithScriptTags(el);
constructor(contentEl:Element) {
this._replaceContentElementWithScriptTags(contentEl);
this.nodes = [];
}
// Inserts the nodes in between the start and end scripts.
// Previous content is removed.
insert(nodes:List<Node>) {
this.nodes = nodes;
DOM.insertAllBefore(this.endScript, nodes);
this._removeNodesUntil(ListWrapper.isEmpty(nodes) ? this.endScript : nodes[0]);
}
// Replaces the content tag with a pair of script tags
_replaceContentElementWithScriptTags(contentEl:Element) {
this.beginScript = DOM.clone(_scriptTemplate);
this.endScript = DOM.clone(_scriptTemplate);
@ -60,7 +62,6 @@ class RenderedContent extends ContentStrategy {
*/
class IntermediateContent extends ContentStrategy {
destinationLightDom:LightDom;
nodes:List<Node>;
constructor(destinationLightDom:LightDom) {
this.destinationLightDom = destinationLightDom;
@ -95,4 +96,4 @@ export class Content {
insert(nodes:List<Node>) {
this._strategy.insert(nodes);
}
}
}

View File

@ -24,8 +24,11 @@ class _Root {
// TODO: LightDom should implement SourceLightDom and DestinationLightDom
// once interfaces are supported
export class LightDom {
// The light DOM of the element is enclosed inside the lightDomView
lightDomView:View;
// The shadow DOM
shadowDomView:View;
// The nodes of the light DOM
nodes:List<Node>;
roots:List<_Root>;
@ -47,6 +50,7 @@ export class LightDom {
return this._collectAllContentTags(this.shadowDomView, []);
}
// Collects the Content directives from the view and all its child views
_collectAllContentTags(view: View, acc:List<Content>):List<Content> {
var eis = view.elementInjectors;
for (var i = 0; i < eis.length; ++i) {
@ -66,6 +70,10 @@ export class LightDom {
return acc;
}
// Collects the nodes of the light DOM by merging:
// - nodes from enclosed ViewPorts,
// - nodes from enclosed content tags,
// - plain DOM nodes
expandedDomNodes():List {
var res = [];
@ -90,6 +98,8 @@ export class LightDom {
return res;
}
// Returns a list of Roots for all the nodes of the light DOM.
// The Root object contains the DOM node and its corresponding injector (could be null).
_roots() {
if (isPresent(this.roots)) return this.roots;
@ -101,6 +111,7 @@ export class LightDom {
}
}
// Projects the light DOM into the shadow DOM
function redistributeNodes(contents:List<Content>, nodes:List<Node>) {
for (var i = 0; i < contents.length; ++i) {
var content = contents[i];