You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/polymer/binding-types.md
+25-26Lines changed: 25 additions & 26 deletions
Original file line number
Diff line number
Diff line change
@@ -12,18 +12,18 @@ subtitle: Data-binding
12
12
There are several ways to bind data to a template. You can:
13
13
14
14
* Create a single instance of a template, by specifying a single object using the `bind` attribute.
15
-
* Create multiple instances of a template, by specifying an array of objects using the `repeat`
15
+
* Create multiple instances of a template, by specifying an array of objects using the `repeat`
16
16
attribute.
17
17
* Conditionally create an instance of a template, depending on whether the value passed to the `if`attribute is truthy.
18
18
19
-
**Note:** Binding templates only works inside {{site.project_title}} elements. For example, if a
20
-
`<template>` element is inserted directly into a page’s `<body>` tag, the `bind` attribute
21
-
doesn’t work as described here. If you need to use template binding outside of a
22
-
{{site.project_title}} element, see [Using data binding outside of a {{site.project_title}} element](/docs/polymer/databinding-advanced.html#bindingoutside).
19
+
**Note:** Binding templates only works inside {{site.project_title}} elements. For example, if a
20
+
`<template>` element is inserted directly into a page’s `<body>` tag, the the `bind` attribute
21
+
doesn’t work as described here. If you need to use template binding outside of a
22
+
{{site.project_title}} element, see [Using data binding outside of a {{site.project_title}} element](/docs/polymer/databinding-advanced.html#bindingoutside).
23
23
{: .alert .alert-info }
24
24
25
-
When you use a binding _inside_ a template, you create a _node binding_, which binds a model value to a
26
-
DOM node. Node bindings are interpreted by the node, based on the element type and where the binding
25
+
When you use a binding _inside_ a template, you create a _node binding_, which binds a model value to a
26
+
DOM node. Node bindings are interpreted by the node, based on the element type and where the binding
27
27
occurs. See [Node bindings](#node-bindings) for details.
28
28
29
29
## Single template instances
@@ -37,9 +37,9 @@ Using the `bind` attribute, you can create a single instance of a template bound
37
37
</template>
38
38
{% endraw %}
39
39
40
-
Where `person` is an object (or more accurately, a [{{site.project_title}} expression](#expressions) that yields an object).
40
+
Where `person` is an object (or more accurately, a [{{site.project_title}} expression](/docs/polymer/expressions.html) that yields an object).
41
41
42
-
Bindings inside the template are evaluated in the context of the bound object. For example,
42
+
Bindings inside the template are evaluated in the context of the bound object. For example,
43
43
if `person` has a property, `name`, {%raw%}`{{name}}`{%endraw%} evaluates to the value of `person.name`.
44
44
45
45
For convenience, you can also create a _named scope_ when binding an object:
@@ -51,7 +51,7 @@ For convenience, you can also create a _named scope_ when binding an object:
51
51
</template>
52
52
{% endraw %}
53
53
54
-
In this case, you can use the named scope `p` to access the properties of the `person` object.
54
+
In this case, you can use the named scope `p` to access the properties of the `person` object.
55
55
Named scopes can be handy when nesting templates.
56
56
57
57
@@ -131,7 +131,7 @@ Conditional templates use the `if` attribute to conditionally create a template
131
131
</template>
132
132
{% endraw %}
133
133
134
-
The conditional template can be explicitly bound to an object using the
134
+
The conditional template can be explicitly bound to an object using the
135
135
{%raw%}`bind={{expression}}`{%endraw%} syntax.
136
136
137
137
Where the explicit binding is omitted, a nested template can inherit the scope of
@@ -145,7 +145,7 @@ the containing template. Conditional templates are frequently used this way:
145
145
</template>
146
146
{% endraw %}
147
147
148
-
For more information on nesting templates, see [Expression scopes](#expression-scopes).
148
+
For more information on nesting templates, see [Expression scopes](/docs/polymer/expressions.html#expression-scopes).
149
149
150
150
You can also use `if` with the `repeat` attribute.
151
151
@@ -157,9 +157,9 @@ You can also use `if` with the `repeat` attribute.
157
157
</template>
158
158
{% endraw %}
159
159
160
-
## Importing templates by reference
160
+
## Importing templates by reference
161
161
162
-
Sometimes, you may want to reuse a template in multiple places, or reference a template generated elsewhere.
162
+
Sometimes, you may want to reuse a template in multiple places, or reference a template generated elsewhere.
163
163
That's where the `ref` attribute comes in:
164
164
165
165
{% raw %}
@@ -187,7 +187,7 @@ You can use the `ref` attribute to define recursive templates, such as tree stru
187
187
</template>
188
188
{% endraw %}
189
189
190
-
In addition, you can bind to the `ref` attribute _itself_, to choose templates dynamically:
190
+
In addition, you can bind to the `ref` attribute _itself_, to choose templates dynamically:
191
191
192
192
{% raw %}
193
193
<templatebindref="{{node.nodeType}}"></template>
@@ -205,13 +205,13 @@ How nodes interpret bindings depends on the _type of element_, and the _binding
205
205
206
206
### Binding to text
207
207
208
-
If a binding occurs between tags, it creates a `textContent` binding to the element.
208
+
If a binding occurs between tags, it creates a `textContent` binding to the element.
209
209
210
210
{% raw %}
211
211
<p>This paragraph has some {{adjective}} text.</p>
212
212
{% endraw %}
213
213
214
-
All text nodes treat a `textContent`bindingas a one-way binding: changing the model changes the bound node, but imperatively changing the DOM value does _not_ update the model.
214
+
All text nodes treat a `textContent`binding as a one-way binding: changing the model changes the bound node, but imperatively changing the DOM value does _not_ update the model.
215
215
216
216
### Binding to attributes
217
217
@@ -244,7 +244,7 @@ Two-way bindings are supported as a special case on some user input elements. Sp
244
244
245
245
When you bind to a [published property](polymer.html#published-properties) on a {{site.project_title}} element, you get a two-way binding to the property.
246
246
247
-
In the following sample, the `intro-tag` binds to a published property on the `say-hello` element:
247
+
In the following sample, the `intro-tag` binds to a published property on the `say-hello` element:
248
248
249
249
{% raw %}
250
250
<!-- say-hello element publishes the 'name' property -->
@@ -273,19 +273,19 @@ In the following sample, the `intro-tag` binds to a published property on the `s
273
273
{% endraw %}
274
274
275
275
Here, `yourName` is bound to _both_ the `say-hello` element's `name` property and
276
-
the `input` element's `value` attribute. Both bindings are two-way, so when the user enters
277
-
a name, it's pushed into the `say-hello` element's `name` property. If you change the
276
+
the `input` element's `value` attribute. Both bindings are two-way, so when the user enters
277
+
a name, it's pushed into the `say-hello` element's `name` property. If you change the
278
278
value of the `name` property, the value is pushed into the `input` element.
279
279
280
-
**Note:** The `intro-tag` element doesn't define a `yourName` property. In this case, the data
280
+
**Note:** The `intro-tag` element doesn't define a `yourName` property. In this case, the data
281
281
binding system creates the property automatically.
282
282
{: .alert .alert-info }
283
283
284
284
285
285
#### Binding objects and arrays to published properties
286
286
287
-
Most of the examples show data binding with simple string values,
288
-
but {{site.project_title}} lets you bind references between elements
287
+
Most of the examples show data binding with simple string values,
288
+
but {{site.project_title}} lets you bind references between elements
289
289
using published properties.
290
290
291
291
Let's modify the `name-tag` example to take an object instead of individual
@@ -354,13 +354,12 @@ If _boolean-expression_ is truthy, _attribute_ appears in the markup; otherwise
354
354
355
355
Sometimes, you may not need dynamic bindings. For these cases, there are one-time bindings.
356
356
357
-
Anywhere you use {% raw %}`{{}}`{% endraw %} in expressions, you can use double brackets
357
+
Anywhere you use {% raw %}`{{}}`{% endraw %} in expressions, you can use double brackets
358
358
(`[[]]`) to set up a one-time binding. The binding becomes inactive after {{site.project_title}}
359
359
sets its value for the first time.
360
360
361
361
Example:
362
362
363
363
<input type="text" value="this value is inserted once: [[ obj.value ]]">
364
364
365
-
One-time bindings can potentially be a performance win if you don't need the overhead of setting up property observation.
366
-
365
+
One time bindings can potentially be a performance win if you don't need the overhead of setting up property observation.
Copy file name to clipboardExpand all lines: docs/polymer/polymer.md
+24-23Lines changed: 24 additions & 23 deletions
Original file line number
Diff line number
Diff line change
@@ -25,7 +25,7 @@ At the heart of {{site.project_title}} are [Custom Elements](/platform/custom-el
25
25
26
26
### Attributes
27
27
28
-
{{site.project_title}} [reserves](https://github.com/Polymer/polymer/blob/master/src/declaration/attributes.js#L53) special attributes to be used on `<polymer-element>`:
28
+
{{site.project_title}} reserves special attributes to be used on `<polymer-element>`:
@@ -119,22 +119,22 @@ Elements can be registered in pure JavaScript like so:
119
119
</polymer-element>';
120
120
// The custom elements polyfill can't see the <polymer-element>
121
121
// unless you put it in the DOM.
122
-
document.body.appendChild(el);
122
+
document.body.appendChild(el);
123
123
</script>
124
124
125
125
<name-tag name="John"></name-tag>
126
126
127
-
Note that you need to add the `<polymer-element>` to the document so that the
127
+
Note that you need to add the `<polymer-element>` to the document so that the
128
128
Custom Elements polyfill picks it up.
129
-
129
+
130
130
### Adding public properties and methods {#propertiesmethods}
131
131
132
132
If you wish to define methods/properties on your element (optional), pass an object
133
133
as the second argument to `Polymer()`. This object is used to define
134
134
the element's `prototype`.
135
135
136
136
The following example defines a property `message`, a computed property `greeting`
137
-
using an ES5 getter, and a method `foo`:
137
+
using an ES5 getter, and a method `foo`:
138
138
139
139
<polymer-element name="tag-name">
140
140
<template>{{greeting}}</template>
@@ -143,7 +143,7 @@ using an ES5 getter, and a method `foo`:
143
143
message: "Hello!",
144
144
get greeting() {
145
145
return this.message + ' there!';
146
-
},
146
+
},
147
147
foo: function() {...}
148
148
});
149
149
</script>
@@ -152,7 +152,7 @@ using an ES5 getter, and a method `foo`:
152
152
**Note:**`this` references the custom element itself inside a {{site.project_title}} element. For example, `this.localName == 'tag-name'`.
153
153
{: .alert .alert-info }
154
154
155
-
**Important:** Be careful when initializing properties that are objects or arrays. Due to the nature of `prototype`, you may run into unexpected "shared state" across instances of the same element. If you're initializing an array or object, do it in the `created` callback rather than directly on the `prototype`.
155
+
**Important:** Be careful when initializing properties that are objects or arrays. Due to the nature of `prototype`, you may run into unexpected "shared state" across instances of the same element. If you're initializing an array or object, do it in the `created` callback rather than directly on the `prototype`.
156
156
157
157
// Good!
158
158
Polymer('x-foo', {
@@ -256,7 +256,7 @@ The main page configures the globals by passing attributes:
256
256
{{site.project_title}} has first class support for the Custom Element lifecycle
257
257
callbacks, though for convenience, implements them with shorter names.
258
258
259
-
All of the lifecycle callbacks are optional:
259
+
All of the lifecycle callbacks are optional:
260
260
261
261
Polymer('tag-name', {
262
262
created: function() { ... },
@@ -277,7 +277,7 @@ Spec | {{site.project_title}} | Called when
277
277
|-
278
278
createdCallback | created | An instance of the element is created.
279
279
- | ready | The `<polymer-element>` has been fully prepared (e.g. Shadow DOM created, property observers setup, event listeners attached, etc).
280
-
attachedCallback | attached | An instance of the element was inserted into the DOM.
280
+
attachedCallback | attached | An instance of the element was inserted into the DOM.
281
281
- | 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.
282
282
detachedCallback | detached | An instance was removed from the DOM.
283
283
attributeChangedCallback | attributeChanged | An attribute was added, removed, or updated. **Note**: to observe changes to [published properties](#published-properties), use [changed watchers](#change-watchers).
@@ -453,7 +453,7 @@ When attribute values are converted to property values, {{site.project_title}}
453
453
attempts to convert the value to the correct type, depending on the default
454
454
value of the property.
455
455
456
-
For example, suppose an `x-hint` element has a `count` property that defaults to `0`.
456
+
For example, suppose an `x-hint` element has a `count` property that defaults to `0`.
457
457
458
458
<x-hint count="7"></x-hint>
459
459
@@ -465,7 +465,7 @@ double-quoted JSON string. For example:
This is equivalent to setting the element's `fullname` property to an object
468
+
This is equivalent to setting the element's `fullname` property to an object
469
469
literal in JavaScript:
470
470
471
471
xname.fullname = { first: 'Bob', last: 'Dobbs' };
@@ -648,7 +648,7 @@ All properties on {{site.project_title}} elements can be watched for changes by
648
648
</script>
649
649
</polymer-element>
650
650
651
-
In this example, there are two watched properties, `better` and `best`. The `betterChanged` and `bestChanged` function will be called whenever `better` or `best` are modified, respectively.
651
+
In this example, there are two watched properties, `better` and `best`. The `betterChanged` and `bestChanged` function will be called whenever `better` or `best` are modified, respectively.
@@ -734,7 +734,7 @@ It's important to note that **{{site.project_title}} does not call the <code><em
734
734
735
735
### Automatic node finding
736
736
737
-
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.
737
+
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.
738
738
739
739
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`.
### Observing changes to light DOM children {#onMutation}
866
866
867
-
To know when light DOM children change, you can setup a Mutation Observer to
868
-
be notified when nodes are added or removed. To make this more convenient, {{site.project_title}} adds an `onMutation()` callback to every element. Its first argument is the DOM element to
867
+
To know when light DOM children change, you can setup a Mutation Observer to
868
+
be notified when nodes are added or removed. To make this more convenient, {{site.project_title}} adds an `onMutation()` callback to every element. Its first argument is the DOM element to
869
869
observe. The second argument is a callback which is passed the `MutationObserver` and the mutation records:
870
870
871
871
this.onMutation(domElement, someCallback);
@@ -953,7 +953,7 @@ declared in markup.
953
953
954
954
If you instantiate an element (e.g. `document.createElement('x-foo')`) and do **not** add it to the DOM,
955
955
{{site.project_title}} asynchronously removes its {%raw%}`{{}}`{%endraw%} bindings and `*Changed` methods.
956
-
This helps prevent memory leaks, ensuring the element will be garbage collected.
956
+
This helps prevent memory leaks, ensuring the element will be garbage collected.
957
957
958
958
If you want the element to "remain active" when it's not in the `document`,
959
959
call `cancelUnbindAll()` right after you create or remove it. The [lifecycle methods](#lifecyclemethods)
@@ -998,7 +998,7 @@ when `Object.observe()` is available. When it's not supported, {{site.project_ti
998
998
999
999
`Platform.flush()` is part of {{site.project_title}}'s data observation polyfill, [observe-js](https://github.com/Polymer/observe-js). It dirty check's all objects that have been observed and ensures notification callbacks are dispatched. {{site.project_title}} automatically calls `Platform.flush()` periodically, and this should be sufficient for most application workflows. However, there are times when you'll want to call `Platform.flush()` in application code.
1000
1000
1001
-
**Note**: on platforms that support `Object.observe()` natively, `Platform.flush()` does nothing.
1001
+
**Note:** on platforms that support `Object.observe()` natively, `Platform.flush()` does nothing.
1002
1002
{: .alert .alert-info }
1003
1003
1004
1004
#### When should I call `Platform.flush()`?
@@ -1012,6 +1012,7 @@ need to manually call `Platform.flush()`. Here are specific examples:
1012
1012
2. The author of a slider element wants to ensure that data can propagate from it as the user slides the slider. A user of the element, might, for example, bind the slider's value to an input and expect to see the input change while the slider is moving. To achieve this, the element author calls `Platform.flush()` after setting the element's value in the `ontrack` event handler.
1013
1013
1014
1014
**Note:** {{site.project_title}} is designed such that change notifications are asynchronous. Both `Platform.flush()` and `Object.observe()` (after which it's modeled) are asynchronous. Therefore, **`Platform.flush()` should not be used to try to enforce synchronous data notifications**. Instead, always use [change watchers](#change-watchers) to be informed about state.
1015
+
{: .alert .alert-info }
1015
1016
1016
1017
### How {{site.project_title}} elements prepare themselves {#prepare}
1017
1018
@@ -1037,7 +1038,7 @@ prepare themselves even when they do not satisfy the above rules.
1037
1038
1038
1039
### Resolving paths of sibling elements {#resolvepath}
1039
1040
1040
-
For the general case of element re-use and sharing, URLs in HTML Imports are meant to be relative to the location of the import. The majority of the time, the browser takes care of this for you.
1041
+
For the general case of element re-use and sharing, URLs in HTML Imports are meant to be relative to the location of the import. The majority of the time, the browser takes care of this for you.
1041
1042
1042
1043
However, JavaScript doesn't have a notion of a local import. Therefore, {{site.project_title}} provides a `resolvePath()` utility for converting paths relative to the import to paths relative to the document.
0 commit comments