Skip to content

Commit 6de6398

Browse files
committed
Merge branch 'master' of https://github.com/Polymer/docs
2 parents 9483975 + 2626564 commit 6de6398

File tree

7 files changed

+130
-17
lines changed

7 files changed

+130
-17
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
node_modules
22
bower_components
3-
components
3+
/components
44
polymer-all
55
_site
66
.DS_Store

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Polymer docs are mostly in Markdown with some HTML. [Jekyll][jekyll] is used to
55
We use Jekyll 2.0+ and [Grunt][grunt] to generate the documentation, and compass to compile SASS to CSS. You'll need to install the requirements before working on the docs (these instructions assume [NPM is already installed](http://nodejs.org/download/)):
66

77
gem install jekyll kramdown jekyll-page-hooks compass rouge
8-
npm install -g grunt-cli
8+
npm install -g grunt-cli vulcanize
99

1010
**Note:** If you receive permission warnings, you may need to run the above tasks with `sudo`.
1111

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<link rel="import" href="/samples/components/computed-property.html">
2+
3+
<!-- <link rel="import" href="/elements/demo-tabs.html"> -->
4+
5+
<demo-tabs selected="0">
6+
<demo-tab heading="square-element.html">
7+
{% highlight html %}
8+
{% include_external samples/components/computed-property.html %}
9+
{% endhighlight %}
10+
</demo-tab>
11+
<demo-tab heading="index.html">
12+
{% highlight html %}
13+
<!DOCTYPE html>
14+
<html>
15+
<head>
16+
<script src="platform.js"></script>
17+
<link rel="import" href="square-element.html">
18+
</head>
19+
<body>
20+
<square-element></square-element>
21+
</body>
22+
</html>
23+
{% endhighlight %}
24+
</demo-tab>
25+
<div class="result">
26+
<square-element></square-element>
27+
</div>
28+
</demo-tabs>

docs/polymer/expressions.md

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ Within a `<polymer-element>` you can use {{site.project_title}}'s [expression
1414
library](https://github.com/polymer/polymer-expressions) to write inline expressions,
1515
named scopes, and iterative markup, anywhere {%raw%}`{{`&nbsp;`}}`{%endraw%} bindings are used.
1616

17+
Expressions can also be used to define [computed properties](/docs/polymer/polymer.html#computed-properties).
18+
1719
## Expression syntax
1820

1921
{{site.project_title}} supports expressions in {%raw%}`{{}}`{%endraw%} with a strict
@@ -45,27 +47,33 @@ Expressions support the following subset of JavaScript:
4547
| Grouping (parenthesis) | `(a + b) * (c + d)` |
4648
| Literal values | numbers, strings, `null`, `undefined` | Escaped strings and non-decimal numbers are not supported. |
4749
| Array & Object initializers | `[foo, 1]`, `{id: 1, foo: bar}` |
50+
| Function | `reverse(my_list)` | The expression's value is the return value of the function. The function's arguments are observed for changes, and the expression is re-evaluated whenever one of the arguments changes.
4851
{: .first-col-nowrap .responsive-table .expressions-table }
4952

53+
5054
In addition to the JavaScript portion, an expression can also include one or more _filters_, which
5155
modify the output of the JavaScript expression. See [Filtering expressions](#filters) for
5256
information.
5357

5458
## Evaluating expressions
5559

56-
Expressions are parsed when they're within a double-mustache binding:
60+
Expressions are parsed when they're within a binding or computed property declaration:
5761

58-
<pre class="prettyprint">
59-
{%raw%}{{ <var>expression</var> }}{%endraw%}
62+
<pre class="nocode">
63+
{%raw%}<b>{{</b> <var>expression</var> <b>}}</b>{%endraw%}
6064
</pre>
6165

62-
or a one-time binding:
66+
<pre class="nocode">
67+
<b>[[</b> <var>expression</var> <b>]]</b>
68+
</pre>
6369

64-
<pre class="prettyprint">
65-
[[ <var>expression</var> ]]
70+
<pre class="nocode">
71+
<b>computed: {</b>
72+
<var>property_name</var><b>: '</b><var>expression</var><b>'
73+
}</b>
6674
</pre>
6775

68-
The value of the expression is evaluated and the result inserted as the value of the binding:
76+
The value of the expression is evaluated. In a binding, the result inserted as the value of the binding:
6977

7078
{% raw %}
7179
<div>Jill has {{daughter.children.length + son.children.length}} grandchildren</div>
@@ -75,8 +83,9 @@ may result in:
7583

7684
<div>Jill has 100 grandchildren</div>
7785

78-
For standard (double-mustache) bindings, the expression is re-evaluated whenever the value of one or
79-
more paths in the expression changes.
86+
For standard (double-mustache) bindings and computed properties, the
87+
expression is re-evaluated whenever the value of one or more paths
88+
in the expression changes.
8089

8190
## Expression scopes {#expression-scopes}
8291

@@ -85,6 +94,8 @@ are visible. The expressions in `bind`, `repeat` or `if` attributes are evaluate
8594
the parent template. For an element's outermost template, paths and identifiers are
8695
interpreted relative to the element itself (so `this.prop` is available as {%raw%}`prop`{%endraw%}).
8796

97+
For computed properties, the scope of an expression is always the element itself.
98+
8899
Templates that don't include `bind` or `repeat` share the current scope.
89100

90101
A `bind` or `repeat` without an expression is the same as using an expression that
@@ -244,6 +255,8 @@ The code for the `toFixed` filter could look like this:
244255
return Number(value).toFixed(precision);
245256
}
246257

258+
The parameters passed to a filter are observed for changes.
259+
247260
#### Chaining filters
248261

249262
You can also chain filters, passing the output of one filter to another:

docs/polymer/layout-attrs.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,13 @@ For example, to make "Gamma" 2x larger than "Beta" and "Alpha" 3x larger, use `f
9595

9696
<div horizontal layout>
9797
<div flex three>Alpha</div>
98-
<div>Beta</div>
98+
<div flex>Beta</div>
9999
<div flex two>Gamma</div>
100100
</div>
101101

102102
<div horizontal layout class="demo">
103103
<div flex three>Alpha</div>
104-
<div>Beta</div>
104+
<div flex>Beta</div>
105105
<div flex two>Gamma</div>
106106
</div>
107107

@@ -297,4 +297,4 @@ Attribute | Result
297297
<div class="demo">Hidden: <span hidden>Not displayed</span></div>
298298
<div relative style="height: 100px;" class="demo">
299299
<div fit style="background-color: #000;color: white">Fit</div>
300-
</div>
300+
</div>

docs/polymer/polymer.md

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ If you wish to define methods/properties on your element (optional), pass an obj
133133
as the second argument to `Polymer()`. This object is used to define
134134
the element's `prototype`.
135135

136-
The following example defines a property `message`, a computed property `greeting`
136+
The following example defines a property `message`, a property `greeting`
137137
using an ES5 getter, and a method `foo`:
138138

139139
<polymer-element name="tag-name">
@@ -278,7 +278,7 @@ Below is a table of the lifecycle methods according to the Custom Elements
278278
Spec | {{site.project_title}} | Called when
279279
|-
280280
createdCallback | created | An instance of the element is created.
281-
- | ready | The `<polymer-element>` has been fully prepared (e.g. Shadow DOM created, property observers setup, event listeners attached, etc).
281+
- | ready | The `<polymer-element>` has been fully prepared (e.g. shadow DOM created, property observers setup, event listeners attached, etc).
282282
attachedCallback | attached | An instance of the element was inserted into the DOM.
283283
- | domReady | Called when the element's initial set of children are guaranteed to exist. This is an appropriate time to poke at the element's parent or light DOM children. Another use is when you have sibling custom elements (e.g. they're `.innerHTML`'d together, at the same time). Before element A can use B's API/properties, element B needs to be upgraded. The `domReady` callback ensures both elements exist.
284284
detachedCallback | detached | An instance was removed from the DOM.
@@ -599,6 +599,37 @@ In this example, the published property `name` has initial value of `null` and `
599599

600600
For more information see the [Data binding overview](databinding.html).
601601

602+
### Computed properties
603+
604+
In addition to standard published properties, you can define
605+
properties that are computed based on other property values.
606+
607+
Computed properties are defined in the `computed` object on the
608+
element's prototype:
609+
610+
<pre class="nocode">
611+
<b>computed: {</b>
612+
<var>property-name</var><b>: '</b><var>expression</var><b>'
613+
}</b>
614+
</pre>
615+
616+
Each computed property is defined by a property name and a
617+
[Polymer expression](/docs/polymer/expressions.html). The value
618+
of the computed property is updated dynamically whenever one of
619+
the input values in the expression changes.
620+
621+
In the following example, when you update the input value,
622+
`num`, the computed property `square` updates automatically.
623+
624+
{% include samples/computed-property.html %}
625+
626+
**Limitations**: Currently, computed properties aren't published
627+
so they can't be data bound from _outside_ the element. For example,
628+
you can't bind to the `square` property on `square-element` using
629+
`<square-element square="{%raw%}{{value}}{%endraw%}>`. This
630+
is [a known issue](https://github.com/Polymer/polymer/issues/638).
631+
{: .alert .alert-warning }
632+
602633
### Declarative event mapping
603634

604635
{{site.project_title}} supports declarative binding of events to methods in the component.
@@ -736,7 +767,14 @@ It's important to note that **{{site.project_title}} does not call the <code><em
736767

737768
### Automatic node finding
738769

739-
Another useful feature of {{site.project_title}} is node reference marshalling. Every node in a component's shadow DOM that is tagged with an `id` attribute is automatically referenced in the component's `this.$` hash.
770+
Another useful feature of {{site.project_title}} is automatic node finding.
771+
Nodes in a component's shadow DOM that are tagged with an
772+
`id` attribute are automatically referenced in the component's `this.$` hash.
773+
774+
**Note:** Nodes created dynamically using data binding are _not_ added to the
775+
`this.$` hash. The hash includes only _statically_ created shadow DOM nodes
776+
(that is, the nodes defined in the element's outermost template).
777+
{: .alert .alert-warning }
740778

741779
For example, the following defines a component whose template contains an `<input>` element whose `id` attribute is `nameInput`. The component can refer to that element with the expression `this.$.nameInput`.
742780

@@ -753,6 +791,24 @@ For example, the following defines a component whose template contains an `<inpu
753791
</script>
754792
</polymer-element>
755793

794+
To locate other nodes inside the element's shadow DOM, you can create a
795+
container element with a known ID and use `querySelector` to retrieve
796+
descendants. For example, if your element's template looks like this:
797+
798+
<template>
799+
<div id="container">
800+
<template if="{%raw%}{{some_condition}}{%endraw%}">
801+
<div id="inner">
802+
This content is created by data binding.
803+
</div>
804+
</template>
805+
</div>
806+
</template>
807+
808+
You can locate the inner container using:
809+
810+
this.$.container.querySelector('#inner');
811+
756812
### Firing custom events {#fire}
757813

758814
{{site.project_title}} core provides a convenient `fire()` method for
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<link rel="import" href="../../components/polymer/polymer.html">
2+
3+
<polymer-element name="square-element">
4+
<template>
5+
<input type="number" value="{{num}}"><br>
6+
<em>{{num}}^2 = {{square}}</em>
7+
</template>
8+
<script>
9+
Polymer('square-element', {
10+
num: 2,
11+
computed: {
12+
square: 'num * num'
13+
}
14+
});
15+
</script>
16+
</polymer-element>

0 commit comments

Comments
 (0)