Skip to content

Commit dfc2b5a

Browse files
authored
Merge pull request #32 from nick-woodward/master
Added support for is="dom-bind" allowing for databinding within demo snippet
2 parents b2627ad + 2341e67 commit dfc2b5a

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

demo-snippet.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,9 @@
144144
this._markdown = '```\n' + snippet + '\n' + '```';
145145

146146
// Stamp the template.
147-
Polymer.dom(this).appendChild(document.importNode(template.content, true));
147+
if (!template.is) {
148+
Polymer.dom(this).appendChild(document.importNode(template.content, true));
149+
}
148150
},
149151

150152
_copyToClipboard: function() {

demo/index.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ <h4>Demo of an element with custom styles</h4>
7575
<paper-checkbox checked class="red">Checkbox</paper-checkbox>
7676
</template>
7777
</demo-snippet>
78+
79+
<h4>Demo of an element with bindings</h4>
80+
<demo-snippet class="centered-demo small-text">
81+
<template is="dom-bind">
82+
<paper-checkbox checked="[[active]]">One-Way Binding</paper-checkbox>
83+
<paper-checkbox checked="{{active}}">Two-Way Binding</paper-checkbox>
84+
</template>
85+
</demo-snippet>
7886
</div>
7987
</body>
8088
</html>

test/basic.html

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@
5555
</template>
5656
</demo-snippet>
5757

58+
<demo-snippet id="typeExtensionDemo">
59+
<template is="dom-bind">
60+
<paper-checkbox checked="{{checked}}"></paper-checkbox>
61+
<input value="[[checked]]">
62+
</template>
63+
</demo-snippet>
64+
5865
<script>
5966
suite('display', function() {
6067
var emptyHeight;
@@ -108,6 +115,33 @@
108115
expect(markdownElement.markdown).to.be.equal(
109116
'```\n\n<paper-checkbox disabled></paper-checkbox>\n\n```');
110117
});
118+
119+
test('elements are only rendered once when using a custom type-extension', function() {
120+
var element = document.getElementById('typeExtensionDemo');
121+
122+
// Render the distributed children.
123+
Polymer.dom.flush();
124+
125+
var inputs = element.querySelectorAll('input');
126+
expect(inputs.length).to.be.equal(1);
127+
});
128+
129+
test('can support databinding between elements', function(done) {
130+
var element = document.getElementById('typeExtensionDemo');
131+
var input = Polymer.dom(element).querySelector('input');
132+
var checkbox = Polymer.dom(element).querySelector('paper-checkbox')
133+
134+
// Render the distributed children.
135+
Polymer.dom.flush();
136+
137+
checkbox.set('checked', true);
138+
139+
flush(function() {
140+
expect(checkbox.checked).to.be.equal(true);
141+
expect(input.value).to.be.equal('true');
142+
done();
143+
});
144+
});
111145
});
112146

113147
suite('parsing', function() {

0 commit comments

Comments
 (0)