-
Notifications
You must be signed in to change notification settings - Fork 2k
/
dom-bind.html
191 lines (156 loc) · 5.45 KB
/
dom-bind.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
<!doctype html>
<!--
@license
Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<html>
<head>
<meta charset="utf-8">
<script src="../../../webcomponentsjs/webcomponents-lite.js"></script>
<script src="../../../web-component-tester/browser.js"></script>
</head>
<body>
<template is="dom-bind" id="earlyDomBind">
<div id="earlyBoundChild">{{value}}</div>
</template>
<script>
earlyDomBind.value = 'hi!';
</script>
<link rel="import" href="../../polymer.html">
<link rel="import" href="dom-bind-elements1.html">
<template is="dom-bind" id="decDomBind">
<x-basic id="decEl1" value="{{value}}" notifyingvalue="{{nvalue}}" on-custom="handleEvent" computed="{{compute(dep)}}"></x-basic>
<x-basic id="decEl2" value="{{value}}" notifyingvalue="{{nvalue}}"></x-basic>
</template>
<div id="container">
</div>
<template is="dom-bind" id="timingDomBind" config="config">
<x-needs-host id="needsHost"></x-needs-host>
</template>
<script>
suite('dom-bind touched before upgrade', function() {
test('value binds top-down', function() {
assert.equal(earlyBoundChild.textContent, 'hi!');
});
});
suite('declarative dom-bind', function() {
var domBind;
var el1;
var el2;
setup(function() {
domBind = decDomBind;
el1 = decEl1;
el2 = decEl2;
});
test('value binds top-down', function() {
domBind.value = 'foo';
assert.equal(el1.value, 'foo');
assert.equal(el2.value, 'foo');
});
test('notifyingvalue binds from child to child', function() {
el1.notifyingvalue = 'bar';
assert.equal(domBind.nvalue, 'bar');
assert.equal(el2.notifyingvalue, 'bar');
});
test('event listener fires', function() {
var count = 0;
domBind.handleEvent = function() {
count++;
};
el1.fire('custom');
assert.equal(count, 1);
});
test('inline function runs', function() {
domBind.compute = function(val) {
return val * 10;
};
domBind.dep = 5;
assert.equal(el1.computed, 50);
});
});
suite('imperative dom-bind', function() {
var domBind;
var el1;
var el2;
setup(function() {
domBind = document.createElement('template', 'dom-bind');
var doc = domBind.content.ownerDocument;
el1 = doc.createElement('x-basic');
el1.setAttribute('id', 'impEl1');
el1.setAttribute('value', '{{value}}');
el1.setAttribute('notifyingvalue', '{{nvalue}}');
el1.setAttribute('on-custom', 'handleEvent');
el1.setAttribute('computed', '{{compute(dep)}}');
el2 = doc.createElement('x-basic');
el2.setAttribute('id', 'impEl2');
el2.setAttribute('value', '{{value}}');
el2.setAttribute('notifyingvalue', '{{nvalue}}');
domBind.content.appendChild(el1);
domBind.content.appendChild(el2);
document.body.appendChild(domBind);
CustomElements.takeRecords();
el1 = domBind.$.impEl1;
el2 = domBind.$.impEl2;
});
teardown(function() {
if (domBind.parentElement) {
domBind.parentElement.removeChild(domBind);
}
});
test('value binds top-down', function() {
domBind.value = 'foo';
assert.equal(el1.value, 'foo');
assert.equal(el2.value, 'foo');
});
test('notifyingvalue binds from child to child', function() {
el1.notifyingvalue = 'bar';
assert.equal(domBind.nvalue, 'bar');
assert.equal(el2.notifyingvalue, 'bar');
});
test('event listener fires', function() {
var count = 0;
domBind.handleEvent = function() {
count++;
};
el1.fire('custom');
assert.equal(count, 1);
});
test('inline function runs', function() {
domBind.compute = function(val) {
return val * 10;
};
domBind.dep = 5;
assert.equal(el1.computed, 50);
});
test('move dom-bind', function() {
domBind.parentElement.removeChild(domBind);
// TODO(kschaaf): detached/attached not called if takeRecords isn't
// called between remove & insert on polyfill... seems bad?
CustomElements.takeRecords();
container.appendChild(domBind);
CustomElements.takeRecords();
assert.equal(container.firstElementChild, el1);
assert.equal(container.firstElementChild.nextElementSibling, el2);
});
test('remove dom-bind', function() {
domBind.parentElement.removeChild(domBind);
CustomElements.takeRecords();
assert(!document.body.contains(el1));
assert(!document.body.contains(el2));
});
});
suite('timing', function() {
test('late-loaded import should block stamping', function() {
assert.equal(needsHost.config, 'config');
});
});
</script>
<link rel="import" href="dom-bind-elements2.html">
<link rel="import" href="should-404.html">
</body>
</html>