diff --git a/PRIMER.md b/PRIMER.md index b6564d8266..b615aa6d30 100644 --- a/PRIMER.md +++ b/PRIMER.md @@ -299,15 +299,15 @@ Modules are registered using the `modulate` global function, passing a name to r ```js ``` @@ -317,12 +317,12 @@ A list of module dependencies can be specified as the second parameter, which wi ```js ``` @@ -335,20 +335,20 @@ Modules are requested using the `using` global function, passing a list of depen ``` @@ -386,17 +386,17 @@ Example: `my-element.html` ``` @@ -464,14 +464,14 @@ Polymer provides custom API for manipulating dom such that local DOM and light D Example: -```html - var toLight = document.createElement('div'); - this.lightDom.appendChild(toLight); +```js +var toLight = document.createElement('div'); +this.lightDom.appendChild(toLight); - var toLocal = document.createElement('div'); - this.localDom.insertBefore(toLocal, this.localDom.children()[0]); +var toLocal = document.createElement('div'); +this.localDom.insertBefore(toLocal, this.localDom.children()[0]); - var allSpans = this.localDom.querySelectorAll('span'); +var allSpans = this.localDom.querySelectorAll('span'); ``` For manipulating dom in elements that themselves do not have local dom, the above api's support an extra argument which is the container `node` in which the operation should be performed. @@ -499,13 +499,12 @@ When multiple dom operations need to occur at once time, it's more efficient to Example: -```html +```js this.localDom.batch(function() { - for (var i=0; i<10; i++) { + for (var i = 0; i < 10; i++) { this.localDom.appendChild(document.createElement('div')); } }); - ``` To provide a `local` view of the dom tree from a perspective independent of a custom element, polymer provides the `Polymer.dom` object. This object supports `querySelector/querySelectorAll` for example and the following guarantees that elements inside local DOM will not be seen. @@ -513,7 +512,7 @@ To provide a `local` view of the dom tree from a perspective independent of a cu Example: ```html - Polymer.dom.querySelector('#myId'); +Polymer.dom.querySelector('#myId'); ``` Sometimes it's necessary to access the elements which have been distributed to a given `` insertion point or to know to which `` a given node has been distributed. The `distributedNodes` and `destinationInsertionPoints` respectively provide this information. @@ -521,25 +520,25 @@ Sometimes it's necessary to access the elements which have been distributed to a Example: ```html - -
-
+ +
+
- // x-foo's template - +// x-foo's template + ``` -```js - var div = xFoo.lightDom.querySelector('div'); - var content = xFoo.localDom.querySelector('content'); - var distributed = xFoo.localDom.distributedNodes(content)[0]; - var insertedTo = xFoo.localDom.destinationInsertionPoints()[0]; - - // the following should be true: - assert.equal(distributed, div); - assert.equal(insertedTo, content) +```js +var div = xFoo.lightDom.querySelector('div'); +var content = xFoo.localDom.querySelector('content'); +var distributed = xFoo.localDom.distributedNodes(content)[0]; +var insertedTo = xFoo.localDom.destinationInsertionPoints()[0]; + +// the following should be true: +assert.equal(distributed, div); +assert.equal(insertedTo, content) ``` @@ -550,13 +549,13 @@ The `configure` method is part of an element's lifecycle and is automatically ca Example: ```js - configure: function() { - // return default values of properties - return { - mode: 'auto', - employees: [] - }; - } +configure: function() { + // return default values of properties + return { + mode: 'auto', + employees: [] + }; +} ``` In general, the configure method should only return the object containing default values, and not cause any side-effects on `this` that may interact with children, as these will still be in an un-configured state at this point. Such actions should be done in the [ready callback](#ready-method). @@ -568,9 +567,9 @@ The `ready` method is part of an element's lifecycle and is automatically called Example: ```js - ready: function() { - this.$.ajax.go(); - } +ready: function() { + this.$.ajax.go(); +} ``` @@ -582,9 +581,9 @@ Example: ```html - + + ... @@ -859,7 +858,6 @@ Example 1: Two-way binding Example 2: One-way binding (downward) ```html - + ... @@ -902,7 +900,6 @@ Example 3: One-way binding (downward) Example 4: One-way binding (upward) ```html - ... @@ -979,9 +977,9 @@ Example: ```html - + ``` @@ -1079,29 +1078,29 @@ Polymer supports virtual properties whose values are calculated from other prope ```html - + ``` @@ -1114,23 +1113,23 @@ When a property only "produces" data and never consumes data, this can be made e ```html ``` @@ -1248,15 +1247,15 @@ In the meantime, styling should be done against the composed tree, meaning: ```html - + - ``` @@ -1288,13 +1287,13 @@ Example: ```html - + ``` Note, the `computed` property feature uses `debounce` under the hood to achieve a similar effect. @@ -1332,14 +1331,13 @@ this.user.manager = 'Matt'; this.notifyPath('user.manager', this.user.manager); ``` - ## Repeating elements Repeating templates is moved to a custom element (HTMLTemplateElement type extension called `x-repeat`): ```html ```