Doc(LightDom): add some inline doc
This commit is contained in:
parent
c797a4fbd5
commit
814f3d01ef
|
@ -9,7 +9,7 @@ import {NgElement} from 'core/dom/element';
|
||||||
var _scriptTemplate = DOM.createScriptTag('type', 'ng/content')
|
var _scriptTemplate = DOM.createScriptTag('type', 'ng/content')
|
||||||
|
|
||||||
class ContentStrategy {
|
class ContentStrategy {
|
||||||
nodes;
|
nodes: List<Node>;
|
||||||
insert(nodes:List<Nodes>){}
|
insert(nodes:List<Nodes>){}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,19 +21,21 @@ class ContentStrategy {
|
||||||
class RenderedContent extends ContentStrategy {
|
class RenderedContent extends ContentStrategy {
|
||||||
beginScript:Element;
|
beginScript:Element;
|
||||||
endScript:Element;
|
endScript:Element;
|
||||||
nodes:List<Node>;
|
|
||||||
|
|
||||||
constructor(el:Element) {
|
constructor(contentEl:Element) {
|
||||||
this._replaceContentElementWithScriptTags(el);
|
this._replaceContentElementWithScriptTags(contentEl);
|
||||||
this.nodes = [];
|
this.nodes = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Inserts the nodes in between the start and end scripts.
|
||||||
|
// Previous content is removed.
|
||||||
insert(nodes:List<Node>) {
|
insert(nodes:List<Node>) {
|
||||||
this.nodes = nodes;
|
this.nodes = nodes;
|
||||||
DOM.insertAllBefore(this.endScript, nodes);
|
DOM.insertAllBefore(this.endScript, nodes);
|
||||||
this._removeNodesUntil(ListWrapper.isEmpty(nodes) ? this.endScript : nodes[0]);
|
this._removeNodesUntil(ListWrapper.isEmpty(nodes) ? this.endScript : nodes[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Replaces the content tag with a pair of script tags
|
||||||
_replaceContentElementWithScriptTags(contentEl:Element) {
|
_replaceContentElementWithScriptTags(contentEl:Element) {
|
||||||
this.beginScript = DOM.clone(_scriptTemplate);
|
this.beginScript = DOM.clone(_scriptTemplate);
|
||||||
this.endScript = DOM.clone(_scriptTemplate);
|
this.endScript = DOM.clone(_scriptTemplate);
|
||||||
|
@ -60,7 +62,6 @@ class RenderedContent extends ContentStrategy {
|
||||||
*/
|
*/
|
||||||
class IntermediateContent extends ContentStrategy {
|
class IntermediateContent extends ContentStrategy {
|
||||||
destinationLightDom:LightDom;
|
destinationLightDom:LightDom;
|
||||||
nodes:List<Node>;
|
|
||||||
|
|
||||||
constructor(destinationLightDom:LightDom) {
|
constructor(destinationLightDom:LightDom) {
|
||||||
this.destinationLightDom = destinationLightDom;
|
this.destinationLightDom = destinationLightDom;
|
||||||
|
|
|
@ -24,8 +24,11 @@ class _Root {
|
||||||
// TODO: LightDom should implement SourceLightDom and DestinationLightDom
|
// TODO: LightDom should implement SourceLightDom and DestinationLightDom
|
||||||
// once interfaces are supported
|
// once interfaces are supported
|
||||||
export class LightDom {
|
export class LightDom {
|
||||||
|
// The light DOM of the element is enclosed inside the lightDomView
|
||||||
lightDomView:View;
|
lightDomView:View;
|
||||||
|
// The shadow DOM
|
||||||
shadowDomView:View;
|
shadowDomView:View;
|
||||||
|
// The nodes of the light DOM
|
||||||
nodes:List<Node>;
|
nodes:List<Node>;
|
||||||
roots:List<_Root>;
|
roots:List<_Root>;
|
||||||
|
|
||||||
|
@ -47,6 +50,7 @@ export class LightDom {
|
||||||
return this._collectAllContentTags(this.shadowDomView, []);
|
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> {
|
_collectAllContentTags(view: View, acc:List<Content>):List<Content> {
|
||||||
var eis = view.elementInjectors;
|
var eis = view.elementInjectors;
|
||||||
for (var i = 0; i < eis.length; ++i) {
|
for (var i = 0; i < eis.length; ++i) {
|
||||||
|
@ -66,6 +70,10 @@ export class LightDom {
|
||||||
return acc;
|
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 {
|
expandedDomNodes():List {
|
||||||
var res = [];
|
var res = [];
|
||||||
|
|
||||||
|
@ -90,6 +98,8 @@ export class LightDom {
|
||||||
return res;
|
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() {
|
_roots() {
|
||||||
if (isPresent(this.roots)) return this.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>) {
|
function redistributeNodes(contents:List<Content>, nodes:List<Node>) {
|
||||||
for (var i = 0; i < contents.length; ++i) {
|
for (var i = 0; i < contents.length; ++i) {
|
||||||
var content = contents[i];
|
var content = contents[i];
|
||||||
|
|
Loading…
Reference in New Issue