Skip to content

Commit

Permalink
Merge pull request #3526 from Polymer/fix-3525
Browse files Browse the repository at this point in the history
Makes lazy registration compatible with platforms IE10
  • Loading branch information
kevinpschaaf committed Mar 22, 2016
2 parents 9959279 + 7ad2bff commit e7254d0
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/lib/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@
}
// registration extension point
proto._doBehavior('registered');
// where prototypes are simulated (IE10), element instance
// must be specfically fixed up.
if (settings.usePolyfillProto && proto !== this) {
proto.extend(this, proto);
}
}
},

Expand Down
61 changes: 60 additions & 1 deletion test/unit/lazy-register.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,51 @@
});
</script>

<dom-module id="x-lazy-api">
<template>
<style>
:host {
background: red;
}
</style>
<div id="lazy">{{a}}</div>
</template>
<script>
HTMLImports.whenReady(function() {
Polymer({
is: 'x-lazy-api',
go: sinon.spy()
});
});
</script>
</dom-module>

<dom-module id="x-lazy-binding">
<template>
<style>
:host {
background: red;
}
</style>
<div id="lazy">{{a}}</div>
</template>
<script>
HTMLImports.whenReady(function() {
Polymer({
is: 'x-lazy-binding',
properties: {
a: {
value: 'a',
observer: '_aChanged'
}
},

_aChanged: sinon.spy()
});
});
</script>
</dom-module>

<dom-module id="x-lazy-style">
<template>
<style>
Expand Down Expand Up @@ -78,7 +123,8 @@
test('not registered until first instance', function() {
assert.isFalse(window.XLazy.prototype.registered.called, 'registered called before instance created');
document.createElement('x-lazy');
assert.isTrue(window.XLazy.prototype.registered.called, 'registered not called after instance created');
document.createElement('x-lazy');
assert.isTrue(window.XLazy.prototype.registered.calledOnce, 'registered not called after instance created');
});

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

test('bindings and oservers can register lazily', function() {
var e = document.createElement('x-lazy-binding');
assert.equal(e.$.lazy.textContent, 'a');
assert.isTrue(e._aChanged.calledOnce);
});

test('api can register lazily', function() {
var e = document.createElement('x-lazy-api');
assert.ok(e.go);
e.go();
assert.isTrue(e.go.calledOnce);
});

test('styles shimmed at first instance', function() {
assert.notOk(document.querySelector('style[scope=x-lazy-style]'), 'style shimmed before registration complete');
document.createElement('x-lazy-style');
Expand Down

0 comments on commit e7254d0

Please sign in to comment.