Skip to content

Commit 4834651

Browse files
author
Steven Orvell
committed
Fixes #3525: Makes lazy registration compatible with platforms (like IE10) on which a custom element's prototype must be simulated.
1 parent 9959279 commit 4834651

2 files changed

Lines changed: 65 additions & 1 deletion

File tree

‎src/lib/base.html‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@
6868
}
6969
// registration extension point
7070
proto._doBehavior('registered');
71+
// where prototypes are simulated (IE10), element instance
72+
// must be specfically fixed up.
73+
if (settings.usePolyfillProto) {
74+
proto.extend(this, proto);
75+
}
7176
}
7277
},
7378

‎test/unit/lazy-register.html‎

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,51 @@
3535
});
3636
</script>
3737

38+
<dom-module id="x-lazy-api">
39+
<template>
40+
<style>
41+
:host {
42+
background: red;
43+
}
44+
</style>
45+
<div id="lazy">{{a}}</div>
46+
</template>
47+
<script>
48+
HTMLImports.whenReady(function() {
49+
Polymer({
50+
is: 'x-lazy-api',
51+
go: sinon.spy()
52+
});
53+
});
54+
</script>
55+
</dom-module>
56+
57+
<dom-module id="x-lazy-binding">
58+
<template>
59+
<style>
60+
:host {
61+
background: red;
62+
}
63+
</style>
64+
<div id="lazy">{{a}}</div>
65+
</template>
66+
<script>
67+
HTMLImports.whenReady(function() {
68+
Polymer({
69+
is: 'x-lazy-binding',
70+
properties: {
71+
a: {
72+
value: 'a',
73+
observer: '_aChanged'
74+
}
75+
},
76+
77+
_aChanged: sinon.spy()
78+
});
79+
});
80+
</script>
81+
</dom-module>
82+
3883
<dom-module id="x-lazy-style">
3984
<template>
4085
<style>
@@ -78,7 +123,8 @@
78123
test('not registered until first instance', function() {
79124
assert.isFalse(window.XLazy.prototype.registered.called, 'registered called before instance created');
80125
document.createElement('x-lazy');
81-
assert.isTrue(window.XLazy.prototype.registered.called, 'registered not called after instance created');
126+
document.createElement('x-lazy');
127+
assert.isTrue(window.XLazy.prototype.registered.calledOnce, 'registered not called after instance created');
82128
});
83129

84130
test('registered when `ensureRegisterFinished()` is called', function() {
@@ -88,6 +134,19 @@
88134
assert.isTrue(window.XLazy.prototype.registered.calledOnce, 'registered called more than once');
89135
});
90136

137+
test('bindings and oservers can register lazily', function() {
138+
var e = document.createElement('x-lazy-binding');
139+
assert.equal(e.$.lazy.textContent, 'a');
140+
assert.isTrue(e._aChanged.calledOnce);
141+
});
142+
143+
test('api can register lazily', function() {
144+
var e = document.createElement('x-lazy-api');
145+
assert.ok(e.go);
146+
e.go();
147+
assert.isTrue(e.go.calledOnce);
148+
});
149+
91150
test('styles shimmed at first instance', function() {
92151
assert.notOk(document.querySelector('style[scope=x-lazy-style]'), 'style shimmed before registration complete');
93152
document.createElement('x-lazy-style');

0 commit comments

Comments
 (0)