Skip to content

Commit 8ef68e6

Browse files
author
Arthur Evans
committed
1.0 intro material, article fixes.
1 parent 3644eb1 commit 8ef68e6

27 files changed

+811
-50
lines changed

0.5/articles/accessible-web-components.md

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ tags:
2121

2222
{% include authorship.html %}
2323

24+
{% include old-article-disclaimer.html %}
25+
2426
{% include toc.html %}
2527

2628
## Introduction

0.5/articles/communication.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ article: true
1111
author: ebidel
1212
published: 2013-08-12
1313
updated: 2014-06-29
14-
polymer_version: 0.0.20130808
14+
polymer_version: 0.3.3
1515
description: Common techniques for sharing information between custom elements
1616

1717
tags:
@@ -24,7 +24,7 @@ tags:
2424

2525
{% include authorship.html %}
2626

27-
{% include not-an-intro.html %}
27+
{% include old-article-disclaimer.html %}
2828

2929
{% include toc.html %}
3030

0.5/articles/concatenating-web-components.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ tags:
2121

2222
{% include authorship.html %}
2323

24-
{% include not-an-intro.html %}
24+
{% include old-article-disclaimer.html %}
2525

2626
{% include toc.html %}
2727

0.5/articles/distributing-components-with-bower.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ tags:
2121

2222
{% include authorship.html %}
2323

24-
{% include not-an-intro.html %}
24+
{% include old-article-disclaimer.html %}
2525

2626
{% include toc.html %}
2727

0.5/articles/polymer-xtag-vanilla.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@ tags:
2020
- bower
2121
---
2222

23-
{% include not-an-intro.html %}
23+
{% include authorship.html %}
24+
25+
{% include old-article-disclaimer.html %}
26+
27+
{% include toc.html %}
28+
2429

2530
A number of developers have asked if they can use [Polymer](http://www.polymer-project.org/) with [X-Tag](http://www.x-tags.org/)/[Brick](http://brick.mozilla.io/) or vanilla custom elements. We're happy to say that, yes, custom elements of any variety (be they Polymer, X-Tag or vanilla) can all happily coexist. In this guide we’ll cover what you need to do to get started working with custom elements in an interoperable fashion.
2631

0.5/articles/spa.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ paper-button.blue:hover {
3030

3131
{% include authorship.html %}
3232

33-
{% include not-an-intro.html %}
33+
{% include old-article-disclaimer.html %}
3434

3535
{% include toc.html %}
3636

0.5/articles/unit-testing-elements.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ tags:
1919

2020
{% include authorship.html %}
2121

22-
{% include not-an-intro.html %}
22+
{% include old-article-disclaimer.html %}
2323

2424
{% include toc.html %}
2525

0.5/elements/common_elements.vulcanized.js

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0.5/elements/docs-menu.html

+5-2
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,11 @@
106106
<core-submenu id="0.9" label="Polymer 0.9 (beta)" icon="av:new-releases" class="guide">
107107
<core-item label="About this release"><a href="/0.9/"></a></core-item>
108108
<core-submenu label="Get started" icon="hardware:keyboard-arrow-down" class="guide">
109-
<core-item label="Quick tour of Polymer"><a href="/0.9/docs/start/quick-tour.html"></a></core-item>
110-
<core-item label="Getting the code"><a href="/0.9/docs/start/getting-the-code.html"></a></core-item>
109+
<core-item label="What is Polymer?"><a href="/0.9/docs/start/what-is-polymer.html"></a></core-item>
110+
<core-item label="Quick tour of Polymer"><a href="/0.9/docs/start/quick-tour.html"></a></core-item>
111+
<core-item label="Get the code"><a href="/0.9/docs/start/getting-the-code.html"></a></core-item>
112+
<core-item label="Reusable elements"><a href="/0.9/docs/start/reusableelements.html"></a></core-item>
113+
111114
</core-submenu>
112115
<core-submenu label="Developer guide" icon="hardware:keyboard-arrow-down" class="guide">
113116
<core-item label="Feature overview"><a href="/0.9/docs/devguide/feature-overview.html"></a></core-item>

0.5/elements/homepage_elements.vulcanized.js

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0.9/articles/index.md

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
---
2+
layout: default
3+
type: guide
4+
shortname: Docs
5+
title: Articles
6+
subtitle: Core concepts of build apps on top of Polymer and web components
7+
8+
add_permalinks: false
9+
---
10+
11+
{% assign articles = (site.pages | where:"article",true %}
12+
{% assign sorted_pages = articles | sort: 'published' | reverse %}
13+
14+
{% for p in sorted_pages %}
15+
16+
{% unless p.draft %}
17+
18+
{% if p.article %}
19+
20+
{% assign pubdate = p.published | date: "%Y-%m-%d" %}
21+
{% assign updated = p.updated | date: "%Y-%m-%d" %}
22+
{% assign author = site.data.authors[p.author] %}
23+
{% assign collaborator = site.data.authors[p.collaborator] %}
24+
{% assign polymer_version = p.polymer_version %}
25+
26+
{::options parse_block_html="true" /}
27+
<div class="article">
28+
{% if polymer_version %}
29+
<span class="forversion">Polymer v{{polymer_version}}</span>
30+
{% endif %}
31+
## [{{ p.title }}]({{ p.url }})
32+
33+
34+
35+
<!-- <span class="tags">
36+
{% for tag in p.tags %}<span>{{ tag }}</span>{% endfor %}
37+
</span> -->
38+
39+
<div class="byline author">
40+
<a href="https://plus.google.com/{{author.gplus}}?rel=author" target="blank_">![{{author.full_name}} profile pic]({{author.profile_pic}} "{{author.full_name}}")</a>
41+
<a href="https://plus.google.com/{{author.gplus}}" target="blank_">{{author.full_name}}</a>
42+
43+
{% if collaborator %}
44+
and <a href="https://plus.google.com/{{collaborator.gplus}}?rel=author" target="blank_">![{{collaborator.full_name}} profile pic]({{collaborator.profile_pic}} "{{collaborator.full_name}}")</a>
45+
<a href="https://plus.google.com/{{collaborator.gplus}}" target="blank_">{{collaborator.full_name}}</a>
46+
{% endif %}
47+
48+
, <time pubdate datetime="{{pubdate}}">{{p.published | date: "%B %Y"}}</time>
49+
50+
{% if p.updated %}(updated <time datetime="{{updated}}">{{updated}}</time>){% endif %}
51+
</div>
52+
53+
<p>{{p.description}}</p>
54+
55+
</div>
56+
{% endif %}
57+
58+
{% endunless %}
59+
60+
{% endfor %}
61+
62+
<div style="margin-top:5em;">
63+
_Have an idea for an article? [Suggest it](https://github.com/Polymer/docs/issues/new)!_
64+
</div>

0.9/articles/shadydom.md

+216
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,216 @@
1+
---
2+
layout: default
3+
type: guide
4+
shortname: Articles
5+
title: "What is shady DOM?"
6+
subtitle: Why do we need a new kind of DOM?
7+
8+
article: true
9+
description: Why do we need a new kind of DOM?
10+
published: 2015-05-28
11+
#updated: 2014-10-17
12+
author: sjmiles
13+
polymer_version: "1.0"
14+
15+
tags:
16+
- shadowdom
17+
- shadydom
18+
---
19+
20+
21+
{% include authorship.html %}
22+
23+
{% include toc.html %}
24+
25+
## Why a new kind of DOM?
26+
27+
Encapsulation is at the core of web components.
28+
29+
Web components aim to provide the user a **simple element interface** that is
30+
rendered with **complexity hidden under the hood.**
31+
32+
Browsers often do this kind of encapsulation internally. Elements like
33+
`<select>` or `<video>` are rendered as unreachable DOM subtrees, only the
34+
browser vendors really know what’s in there.
35+
36+
There are libraries today that do this sort of thing via JavaScript. For
37+
example, JQuery plugins allow you to target an element and imbue it with
38+
abilities. Often a plugin will generate a bunch of DOM for you; this is how it
39+
adds value. However, these plugin elements are not quite as nifty as `<select>`
40+
or `<video>` because the DOM used to render the control ends up just sitting
41+
there in your document, not hidden away.
42+
43+
The shadow DOM standard is aimed at bridging this gap. On browsers that support
44+
shadow DOM, it’s possible to have an element that is rendered with complex DOM,
45+
but have that complexity hidden away as implementation detail. Simple Markup is
46+
Good
47+
48+
Let’s imagine an `x-fade` element that makes an image fade-in when it loads. You
49+
use it like this:
50+
51+
<x-fade>
52+
<img src="cool.png">
53+
</x-fade>
54+
55+
Let’s imagine we implement this element as a JQuery plugin, and the user “renders” the element this way:
56+
57+
$('x-fade').makeFade();
58+
59+
The author is happy, because `x-fade` is doing its thing now.
60+
61+
This is the virtue we want from Web Components: the author has used some simple
62+
markup to acquire fancy functionality. But Web Components makes this experience
63+
even better. The plugin version has problems with its DOM; problems that are
64+
solved by shadow DOM.
65+
66+
## DOM Pollution
67+
68+
After the `makeFade` call, let’s say the DOM looks something like this:
69+
70+
<x-fade>
71+
<div>
72+
<img src="cool.png">
73+
</div>
74+
<canvas></canvas>
75+
</x-fade>
76+
77+
`x-fade needs to add some DOM elements to implement its behavior. Sadly, these
78+
elements are now exposed to the world. Exposing these nodes is problematic:
79+
80+
81+
- Details of the implementation are leaking.
82+
- Queries over the document now include the `<canvas>` and the `<div>`.
83+
- The new nodes may be affected by stylesheets, because the document author wasn’t expecting them.
84+
- The `<img>` node may lose styling, because it’s in a different part of the DOM tree now.
85+
- Can the developer add a new `<img>` or replace the old one? How can she do that, if the node is not where she left it?
86+
87+
88+
## Tree Scoping
89+
90+
This is where shadow DOM comes in, or more generally speaking, there is where
91+
_tree-scoping_ comes in. Tree-scoping is the ability to take a DOM subtree and
92+
hide it from the main document scope. This is where the shadow nomenclature
93+
comes from, as if we are hiding some DOM in the shadows (which is awesome, but
94+
unfortunately sounds a bit nefarious).
95+
96+
If `x-fade` is implemented with shadow DOM, then after calling `makeFade`, the DOM tree looks like this:
97+
98+
<x-fade>
99+
<img src="cool.png">
100+
</x-fade>
101+
102+
That is, exactly how it was before makeFade, which is the point.
103+
104+
The rendering is just as fancy, but from the developer’s perspective, it’s just
105+
one node with one child, just as she wrote it.
106+
107+
So tree scoping with shadow DOM has solved our problems with the previous
108+
implementation. Specifically:
109+
110+
- Details of the implementation are hidden.
111+
- Queries over the document will not see the `<canvas>` or the `<div>`.
112+
- The new nodes are not affected by stylesheets, because they are not in the document scope.
113+
- The `<img>` node will not lose styling, because it never moves.
114+
- The developer can add a new `<img>` or replace the old one, it’s just a regular child of `x-fade`.
115+
116+
## Shadow DOM Encapsulation
117+
118+
If we draw a picture of the DOM that includes the shadow root, we can see where the extra goodies are:
119+
120+
<x-fade>
121+
<img src="cool.png">
122+
#shadow-root
123+
<div>
124+
<content select="img">
125+
</div>
126+
<canvas></canvas>
127+
</x-fade>
128+
129+
OK, there’s our `<canvas>` and our `<div>` (and one other new thing: the `<content>`
130+
node, this is the bit that tells the browser where and how to combine the
131+
element's shadow tree with its regular children).
132+
133+
At render time, the element's children and shadow tree are _composed_ into a
134+
single tree for rendering. In this case, the _composed tree_ looks just like the
135+
classic jQuery version shown before:
136+
137+
<x-fade>
138+
<div>
139+
<img src="cool.png">
140+
</div>
141+
<canvas></canvas>
142+
</x-fade>
143+
144+
## Shadow DOM is awesome, why is there a shady DOM?
145+
146+
Shadow DOM works by hiding the scoped DOM trees from the traditional tree
147+
walking functions and accessors (`childNodes`, `children`, `firstChild` and so
148+
on). These accessors return only the elements in your scope.
149+
150+
To polyfill shadow DOM turns out to be hard. The polyfill must ensure native DOM
151+
always reflects the composed tree so the platform renders the right thing, while
152+
only ever revealing the logical tree to the developer.
153+
154+
This means that all the tree-walking accessors (`childNodes`, `children`,
155+
`firstChild`, and so on) have to be modified so they return custom information.
156+
To present the logical tree to the developer, one has to wrap the entire DOM API
157+
surface and indirect the responses through custom data structures.
158+
159+
The Shadow DOM Polyfill actually attempts this task, but there are costs:
160+
161+
- It’s a lot of code.
162+
- It’s slow to indirect all the DOM API.
163+
- Structures like `NodeList` can simply not be emulated.
164+
- There are certain accessors that cannot be overwritten (for example, `window.document`, `window.document.body`).
165+
- The polyfill returns objects that are not actually Nodes, but Node proxies, which can be very confusing.
166+
167+
Many projects simply cannot afford the Shadow DOM Polyfill, for the reasons
168+
given above. In particular, the performance costs on platforms like mobile
169+
Safari are nearly intolerable.
170+
171+
## Shady DOM is Born
172+
173+
Roughly speaking, shady DOM provides a shadow DOM compatible form of tree
174+
scoping. To go back to our `x-fade` example, the `x-fade` DOM rendered with
175+
shady DOM looks just like the classic JQuery version:
176+
177+
<x-fade>
178+
<div>
179+
<img src="cool.png">
180+
</div>
181+
<canvas></canvas>
182+
</x-fade>
183+
184+
In other words, strictly speaking it has the same deficiencies. It’s leaking
185+
details, confusing CSS, and all the rest.
186+
187+
The saving grace is that if you opt-in to looking at the tree with the shady DOM
188+
API, you can restore the value of shadow DOM. For example, if instead of walking
189+
`<x-fade>`’s subtree using the traditional API, if you examine it using the shady
190+
DOM API, you see this:
191+
192+
<x-fade>
193+
<img src="cool.png">
194+
</x-fade>
195+
196+
“Examine it using the shady DOM API” means something like this:
197+
198+
var arrayOfNodes = Polymer.dom(x-fade).children;
199+
200+
The upshot is that shady DOM provides enough tree-scoping for Polymer to act as
201+
if shadow DOM is available on all platforms, without compromising performance.
202+
203+
It’s important to note that we've made shady DOM and shadow DOM compatible. This
204+
means that the shady DOM API employs real shadow DOM where it's available.
205+
Therefore, you can write one code base that works on all platforms, but you
206+
enjoy improved performance and robustness on platforms that implement Shadow
207+
DOM.
208+
209+
## Summary
210+
211+
- Web components require tree-scoping for proper encapsulation.
212+
- Shadow DOM is the standard that implements tree-scoping, but it’s not yet universally implemented.
213+
- Polyfilling shadow DOM is hard, the robust polyfill is invasive and slow.
214+
- Shady DOM is a super-fast shim for shadow DOM that provides tree-scoping, but has drawbacks. Most importantly, one must use the shady DOM APIs to work with scoped trees.
215+
- Shady DOM makes web components palatable for a much wider swath of projects, growing mindshare, and driving adoption of all web components standards.
216+
- The annoying bits of shady DOM are exactly the reasons why shadow DOM needs to be native across platforms.

0 commit comments

Comments
 (0)