Skip to content

Commit 814f3d0

Browse files
committed
Doc(LightDom): add some inline doc
1 parent c797a4f commit 814f3d0

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

modules/core/src/compiler/shadow_dom_emulation/content_tag.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {NgElement} from 'core/dom/element';
99
var _scriptTemplate = DOM.createScriptTag('type', 'ng/content')
1010

1111
class ContentStrategy {
12-
nodes;
12+
nodes: List<Node>;
1313
insert(nodes:List<Nodes>){}
1414
}
1515

@@ -21,19 +21,21 @@ class ContentStrategy {
2121
class RenderedContent extends ContentStrategy {
2222
beginScript:Element;
2323
endScript:Element;
24-
nodes:List<Node>;
2524

26-
constructor(el:Element) {
27-
this._replaceContentElementWithScriptTags(el);
25+
constructor(contentEl:Element) {
26+
this._replaceContentElementWithScriptTags(contentEl);
2827
this.nodes = [];
2928
}
3029

30+
// Inserts the nodes in between the start and end scripts.
31+
// Previous content is removed.
3132
insert(nodes:List<Node>) {
3233
this.nodes = nodes;
3334
DOM.insertAllBefore(this.endScript, nodes);
3435
this._removeNodesUntil(ListWrapper.isEmpty(nodes) ? this.endScript : nodes[0]);
3536
}
3637

38+
// Replaces the content tag with a pair of script tags
3739
_replaceContentElementWithScriptTags(contentEl:Element) {
3840
this.beginScript = DOM.clone(_scriptTemplate);
3941
this.endScript = DOM.clone(_scriptTemplate);
@@ -60,7 +62,6 @@ class RenderedContent extends ContentStrategy {
6062
*/
6163
class IntermediateContent extends ContentStrategy {
6264
destinationLightDom:LightDom;
63-
nodes:List<Node>;
6465

6566
constructor(destinationLightDom:LightDom) {
6667
this.destinationLightDom = destinationLightDom;
@@ -95,4 +96,4 @@ export class Content {
9596
insert(nodes:List<Node>) {
9697
this._strategy.insert(nodes);
9798
}
98-
}
99+
}

modules/core/src/compiler/shadow_dom_emulation/light_dom.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,11 @@ class _Root {
2424
// TODO: LightDom should implement SourceLightDom and DestinationLightDom
2525
// once interfaces are supported
2626
export class LightDom {
27+
// The light DOM of the element is enclosed inside the lightDomView
2728
lightDomView:View;
29+
// The shadow DOM
2830
shadowDomView:View;
31+
// The nodes of the light DOM
2932
nodes:List<Node>;
3033
roots:List<_Root>;
3134

@@ -47,6 +50,7 @@ export class LightDom {
4750
return this._collectAllContentTags(this.shadowDomView, []);
4851
}
4952

53+
// Collects the Content directives from the view and all its child views
5054
_collectAllContentTags(view: View, acc:List<Content>):List<Content> {
5155
var eis = view.elementInjectors;
5256
for (var i = 0; i < eis.length; ++i) {
@@ -66,6 +70,10 @@ export class LightDom {
6670
return acc;
6771
}
6872

73+
// Collects the nodes of the light DOM by merging:
74+
// - nodes from enclosed ViewPorts,
75+
// - nodes from enclosed content tags,
76+
// - plain DOM nodes
6977
expandedDomNodes():List {
7078
var res = [];
7179

@@ -90,6 +98,8 @@ export class LightDom {
9098
return res;
9199
}
92100

101+
// Returns a list of Roots for all the nodes of the light DOM.
102+
// The Root object contains the DOM node and its corresponding injector (could be null).
93103
_roots() {
94104
if (isPresent(this.roots)) return this.roots;
95105

@@ -101,6 +111,7 @@ export class LightDom {
101111
}
102112
}
103113

114+
// Projects the light DOM into the shadow DOM
104115
function redistributeNodes(contents:List<Content>, nodes:List<Node>) {
105116
for (var i = 0; i < contents.length; ++i) {
106117
var content = contents[i];

0 commit comments

Comments
 (0)