|
103 | 103 | <x-element id="ifElementLD" prop="{{prop}}" path="{{obj.path}}"></x-element> |
104 | 104 | </template> |
105 | 105 | </template> |
| 106 | + <template id="templateWithDifferentProps"> |
| 107 | + <div id="bound">[[otherProp]]</div> |
| 108 | + </template> |
106 | 109 | <script> |
107 | 110 | HTMLImports.whenReady(() => { |
108 | 111 | class XRuntime extends Polymer.GestureEventListeners(Polymer.Element) { |
|
114 | 117 | this.pathChanged = sinon.spy(); |
115 | 118 | this.prop = 'prop'; |
116 | 119 | this.obj = {path: 'obj.path'}; |
117 | | - this.shadowTemplates = []; |
118 | 120 | } |
119 | 121 | ready() { |
120 | 122 | super.setAttribute('log', ''); |
|
134 | 136 | this.shadowRoot.appendChild(dom); |
135 | 137 | return dom; |
136 | 138 | } |
| 139 | + stampTemplateWithDifferentProps() { |
| 140 | + let dom = this._stampTemplate(Polymer.DomModule.import(this.localName, '#templateWithDifferentProps')); |
| 141 | + this.shadowRoot.appendChild(dom); |
| 142 | + return dom; |
| 143 | + } |
137 | 144 | } |
138 | 145 | customElements.define('x-runtime', XRuntime); |
139 | 146 | }); |
|
162 | 169 | static _parseTemplateNodeAttribute(node, templateInfo, nodeInfo, name, value) { |
163 | 170 | if (name == 'special') { |
164 | 171 | nodeInfo.specialAttr = value; |
165 | | - nodeInfo.infoIndex = templateInfo.nodeInfoList.length; |
166 | 172 | node.removeAttribute('special'); |
167 | 173 | node.setAttribute('had-special', ''); |
168 | 174 | return true; |
|
173 | 179 | static _parseTemplateNode(node, templateInfo, nodeInfo) { |
174 | 180 | let noted = super._parseTemplateNode(node, templateInfo, nodeInfo); |
175 | 181 | if (node.localName == 'x-special') { |
176 | | - nodeInfo.infoIndex = templateInfo.nodeInfoList.length; |
177 | 182 | noted = nodeInfo.specialNode = true; |
178 | 183 | } |
179 | 184 | return noted; |
|
215 | 220 | <dom-module id="x-binding"> |
216 | 221 | <template> |
217 | 222 | <x-element id="standard1" prop="[[prop]]" path="[[obj.path]]"></x-element> |
218 | | - <x-element id="custom1" prop='[{"prop": "prop", "prop2": "prop2"}]'></x-element> |
| 223 | + <x-element id="custom1" prop='[{"a": "prop", "b": "prop2"}]'></x-element> |
219 | 224 | <div> |
220 | 225 | <x-element id="standard2" prop="[[prop]]" path="[[obj.path]]"></x-element> |
221 | | - <x-element id="custom2" prop='[{"prop": "prop", "prop2": "prop2"}]'></x-element> |
| 226 | + <x-element id="custom2" prop='[{"a": "prop", "b": "prop2"}]'></x-element> |
222 | 227 | </div> |
223 | | - <template id="domIf" is="dom-if" if="[[prop]]" restamp> |
| 228 | + <template id="domIf" is="dom-if" if="[[prop2]]" restamp> |
224 | 229 | <x-element id="standard3" prop="[[prop]]" path="[[obj.path]]"></x-element> |
225 | | - <x-element id="custom3" prop='[{"prop": "prop", "prop2": "prop2"}]'></x-element> |
| 230 | + <x-element id="custom3" prop='[{"a": "prop", "b": "prop2"}]'></x-element> |
226 | 231 | </template> |
227 | 232 | </template> |
228 | 233 | <script> |
|
367 | 372 | assert.equal(stamped[0], el.$.first); |
368 | 373 | assert.equal(stamped[1], dom1.$.first); |
369 | 374 | // Unstamp |
370 | | - el._unstampTemplate(dom1); |
| 375 | + el._removeBoundDom(dom1); |
371 | 376 | for (let n in dom1.$) { |
372 | 377 | assert.notOk(dom1.$[n].parentNode, null); |
373 | 378 | } |
| 379 | + stamped = el.shadowRoot.querySelectorAll('x-element#first'); |
| 380 | + assert.equal(stamped.length, 1); |
| 381 | + assert.equal(stamped[0], el.$.first); |
374 | 382 | // Stamp again |
375 | 383 | let dom2 = el.stampTemplateFromShadow(); |
376 | 384 | assertStampingCorrect(el, el.$); |
|
405 | 413 | 'x-runtime|x-element#shadow' |
406 | 414 | ]); |
407 | 415 | // Unstamp |
408 | | - el._unstampTemplate(dom2); |
409 | | - el._unstampTemplate(dom3); |
| 416 | + el._removeBoundDom(dom2); |
| 417 | + el._removeBoundDom(dom3); |
410 | 418 | for (let n in dom2.$) { |
411 | 419 | assert.notOk(dom1.$[n].parentNode, null); |
412 | 420 | } |
|
448 | 456 | assert.equal(stamped[0], el.$.first); |
449 | 457 | assert.equal(stamped[1], dom1.$.first); |
450 | 458 | // Unstamp |
451 | | - el._unstampTemplate(dom1); |
| 459 | + el._removeBoundDom(dom1); |
452 | 460 | for (let n in dom1.$) { |
453 | 461 | assert.notOk(dom1.$[n].parentNode, null); |
454 | 462 | } |
|
486 | 494 | 'x-runtime|x-element#light' |
487 | 495 | ]); |
488 | 496 | // Unstamp |
489 | | - el._unstampTemplate(dom2); |
490 | | - el._unstampTemplate(dom3); |
| 497 | + el._removeBoundDom(dom2); |
| 498 | + el._removeBoundDom(dom3); |
491 | 499 | for (let n in dom2.$) { |
492 | 500 | assert.notOk(dom1.$[n].parentNode, null); |
493 | 501 | } |
|
554 | 562 | assertAllPropValues(el, sd, ld, 'path', 'obj.path+++', 4); |
555 | 563 | }); |
556 | 564 |
|
| 565 | + test('accessors for non-prototypically bound properties created', () => { |
| 566 | + // First element |
| 567 | + let dom = el.stampTemplateWithDifferentProps(); |
| 568 | + el.otherProp = 'otherProp'; |
| 569 | + assert.equal(dom.$.bound.textContent, 'otherProp'); |
| 570 | + // Second element |
| 571 | + let el2 = document.createElement('x-runtime'); |
| 572 | + document.body.appendChild(el2); |
| 573 | + let dom2 = el2.stampTemplateWithDifferentProps(); |
| 574 | + el2.otherProp = 'otherProp'; |
| 575 | + assert.equal(dom2.$.bound.textContent, 'otherProp'); |
| 576 | + document.body.removeChild(el2); |
| 577 | + }); |
| 578 | + |
557 | 579 | test('prototypical stamping not affected by runtime stamping', () => { |
558 | 580 | assertStampingCorrect(el, el.$); |
559 | 581 | let stamped = el.shadowRoot.querySelectorAll('x-element#first'); |
|
665 | 687 | assert.equal(el.$.standard1.path, 'obj.path'); |
666 | 688 | assert.equal(el.$.standard2.path, 'obj.path'); |
667 | 689 | assert.equal(el.shadowRoot.querySelector('#standard3').path, 'obj.path'); |
668 | | - assert.equal(el.$.custom1.prop, 'prop prop2'); |
669 | | - assert.equal(el.$.custom2.prop, 'prop prop2'); |
670 | | - assert.equal(el.shadowRoot.querySelector('#custom3').prop, 'prop prop2'); |
| 690 | + assert.equal(el.$.custom1.prop, 'a b'); |
| 691 | + assert.equal(el.$.custom2.prop, 'a b'); |
| 692 | + assert.equal(el.shadowRoot.querySelector('#custom3').prop, 'a b'); |
671 | 693 | el.prop = false; |
672 | | - el.$.domIf.render(); |
673 | 694 | assert.equal(el.$.standard1.prop, false); |
674 | 695 | assert.equal(el.$.standard2.prop, false); |
| 696 | + assert.equal(el.shadowRoot.querySelector('#standard3').prop, false); |
675 | 697 | assert.equal(el.$.standard1.path, 'obj.path'); |
676 | 698 | assert.equal(el.$.standard2.path, 'obj.path'); |
677 | | - assert.notOk(el.shadowRoot.querySelector('#standard3')); |
678 | | - assert.equal(el.$.custom1.prop, 'prop2'); |
679 | | - assert.equal(el.$.custom2.prop, 'prop2'); |
680 | | - assert.equal(el.shadowRoot.querySelector('#custom3')); |
| 699 | + assert.equal(el.shadowRoot.querySelector('#standard3').path, 'obj.path'); |
| 700 | + assert.equal(el.$.custom1.prop, 'b'); |
| 701 | + assert.equal(el.$.custom2.prop, 'b'); |
| 702 | + assert.equal(el.shadowRoot.querySelector('#custom3').prop, 'b'); |
681 | 703 | el.prop = true; |
682 | | - el.$.domIf.render(); |
683 | 704 | assert.equal(el.$.standard1.prop, true); |
684 | 705 | assert.equal(el.$.standard2.prop, true); |
685 | 706 | assert.equal(el.shadowRoot.querySelector('#standard3').prop, true); |
686 | 707 | assert.equal(el.$.standard1.path, 'obj.path'); |
687 | 708 | assert.equal(el.$.standard2.path, 'obj.path'); |
688 | 709 | assert.equal(el.shadowRoot.querySelector('#standard3').path, 'obj.path'); |
689 | | - assert.equal(el.$.custom1.prop, 'prop prop2'); |
690 | | - assert.equal(el.$.custom2.prop, 'prop prop2'); |
691 | | - assert.equal(el.shadowRoot.querySelector('#custom3').prop, 'prop prop2'); |
| 710 | + assert.equal(el.$.custom1.prop, 'a b'); |
| 711 | + assert.equal(el.$.custom2.prop, 'a b'); |
| 712 | + assert.equal(el.shadowRoot.querySelector('#custom3').prop, 'a b'); |
692 | 713 | document.body.removeChild(el); |
693 | 714 | }); |
694 | 715 | }); |
|
0 commit comments