Skip to content

Commit

Permalink
Change isInert to disable-upgrade and feature is now supported on…
Browse files Browse the repository at this point in the history
…ly via the `disable-upgrade` attribute.
  • Loading branch information
Steven Orvell committed Feb 6, 2017
1 parent e1561f6 commit f8f903c
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 59 deletions.
9 changes: 4 additions & 5 deletions src/lib/annotations/annotations.html
Expand Up @@ -66,7 +66,7 @@
// null-array (shared empty array to avoid null-checks)
Polymer.nar = [];

var inertEnabled = Polymer.Settings.enableInert;
var disableUpgradeEnabled = Polymer.Settings.disableUpgradeEnabled;

Polymer.Annotations = {

Expand Down Expand Up @@ -370,11 +370,10 @@
node.setAttribute(origName, '');
}
// Remove annotation
if (inertEnabled && origName === 'is-inert') {
node.setAttribute('is-inert', '');
} else {
node.removeAttribute(origName);
if (disableUpgradeEnabled && name === 'disable-upgrade') {
node.setAttribute(name, '');
}
node.removeAttribute(origName);
// Case hackery: attributes are lower-case, but bind targets
// (properties) are case sensitive. Gambit is to map dash-case to
// camel-case: `foo-bar` becomes `fooBar`.
Expand Down
47 changes: 21 additions & 26 deletions src/lib/base.html
Expand Up @@ -64,14 +64,16 @@
},

createdCallback: function() {
if (Polymer.Settings.enableInert && this.hasAttribute('is-inert')) {
this.__data__ = {
isInert: true
};
this._propertySetter = inertPropertySetter;
} else {
this.__initialize();
if (Polymer.Settings.disableUpgradeEnabled) {
if (this.hasAttribute('disable-upgrade')) {
this._propertySetter = disableUpgradePropertySetter;
this.__data__ = {};
return;
} else {
this.__hasInitialized = true;
}
}
this.__initialize();
},

__initialize: function() {
Expand Down Expand Up @@ -299,30 +301,23 @@
Polymer.Base = Polymer.Base.chainObject(Polymer.Base, HTMLElement.prototype);
Polymer.BaseDescriptors = {};

if (Polymer.Settings.enableInert) {
var disableUpgradePropertySetter;
if (Polymer.Settings.disableUpgradeEnabled) {

var inertPropertySetter = function(property, value) {
this.__data__[property] = value;
var origAttributeChangedCallback = Polymer.Base.attributeChangedCallback;
Polymer.Base.attributeChangedCallback = function(name, oldValue, newValue) {
if (!this.__hasInitialized && name === 'disable-upgrade') {
this.__hasInitialized = true;
this._propertySetter = Polymer.Bind._modelApi._propertySetter;
this.__initialize();
}
origAttributeChangedCallback.call(this, name, oldValue, newValue);
}

var inertDesc = {
configurable: true,
writeable: true,
set: function(val) {
if (!val && this.isInert) {
this.__data__.isInert = false;
this._propertySetter = Polymer.Bind._modelApi._propertySetter;
this.__initialize();
this.removeAttribute('is-inert');
}
},
get: function() {
return this.__data__.isInert;
}
disableUpgradePropertySetter = function(property, value) {
this.__data__[property] = value;
}

Polymer.BaseDescriptors.isInert = inertDesc;
Object.defineProperty(Polymer.Base, 'isInert', inertDesc);
}

if (window.CustomElements) {
Expand Down
2 changes: 1 addition & 1 deletion test/runner.html
Expand Up @@ -93,7 +93,7 @@
'unit/script-after-import-in-head.html',
'unit/globals.html',
'unit/lazy-register.html',
'unit/element-inertness.html'
'unit/element-disable-upgrade.html'
];

if (document.body.createShadowRoot) {
Expand Down
Expand Up @@ -11,10 +11,10 @@
<meta charset="utf-8">
<script src="../../../webcomponentsjs/webcomponents-lite.js"></script>
<script src="../../../web-component-tester/browser.js"></script>
<script>Polymer = {enableInert: true}</script>
<script>Polymer = {disableUpgradeEnabled: true}</script>
<link rel="import" href="../../polymer.html">

<dom-module id="x-inert">
<dom-module id="x-lazy">
<template>
<style>
:host {
Expand All @@ -26,15 +26,15 @@
<script>
HTMLImports.whenReady(function() {
Polymer({
is: 'x-inert'
is: 'x-lazy'
});
});
</script>
</dom-module>

<test-fixture id="simple">
<template>
<x-inert is-inert></x-inert>
<x-lazy disable-upgrade></x-lazy>
</template>
</test-fixture>

Expand Down Expand Up @@ -68,14 +68,14 @@
</script>
</dom-module>

<dom-module id="x-complicated-inert">
<dom-module id="x-complicated-lazy">
<template>
<x-complicated-child id="child" a="{{a}}" is-inert="{{b}}" c="{{c}}"></x-complicated-child>
<x-complicated-child id="child" a="{{a}}" disable-upgrade$="{{b}}" c="{{c}}"></x-complicated-child>
</template>
<script>
HTMLImports.whenReady(function() {
Polymer({
is: 'x-complicated-inert',
is: 'x-complicated-lazy',
properties: {
a: {value: true},
b: {value: true},
Expand All @@ -86,20 +86,20 @@
</script>
</dom-module>

<test-fixture id="databind-inert">
<test-fixture id="databind-lazy">
<template>
<x-complicated-inert></x-complicated-inert>
<x-complicated-lazy></x-complicated-lazy>
</template>
</test-fixture>

<dom-module id="x-complicated-not-inert">
<dom-module id="x-complicated-not-lazy">
<template>
<x-complicated-child id="child" a="{{a}}" is-inert="{{b}}" c="{{c}}"></x-complicated-child>
<x-complicated-child id="child" a="{{a}}" disable-upgrade$="{{b}}" c="{{c}}"></x-complicated-child>
</template>
<script>
HTMLImports.whenReady(function() {
Polymer({
is: 'x-complicated-not-inert',
is: 'x-complicated-not-lazy',
properties: {
a: {value: true},
b: {value: false},
Expand All @@ -110,40 +110,40 @@
</script>
</dom-module>

<test-fixture id="databind-not-inert">
<test-fixture id="databind-not-lazy">
<template>
<x-complicated-not-inert></x-complicated-not-inert>
<x-complicated-not-lazy></x-complicated-not-lazy>
</template>
</test-fixture>

<script>
suite('Element Inertness', function() {
suite('Inert', function() {
suite('Element disableUpgrade', function() {
suite('disable-upgrade', function() {
var el;
setup(function() {
el = fixture('simple');
});
test('does not stamp when inert', function() {
assert.equal(el.isInert, true);
test('does not stamp when lazy', function() {
assert.equal(el.hasAttribute('disable-upgrade'), true);
assert.notOk(el.shadowRoot);
assert.notOk(el.$);
});
test('stamps when isInert is removed', function() {
el.isInert = false;
test('stamps when disableUpgrade is removed', function() {
el.removeAttribute('disable-upgrade');
assert.ok(el.root);
assert.ok(el.$.child);
});
});
suite('Inertness and Databinding', function() {
test('binding to is-inert with true', function() {
var el = fixture('databind-inert');
assert.equal(el.$.child.isInert, true);
suite('disableUpgrade and Databinding', function() {
test('binding to disable-upgrade with true', function() {
var el = fixture('databind-lazy');
assert.equal(el.$.child.hasAttribute('disable-upgrade'), true);
assert.equal(el.$.child.aRan, undefined);
assert.equal(el.$.child.cRan, undefined);
});
test('bindings to is-inert with false', function () {
var el = fixture('databind-not-inert');
assert.notOk(el.$.child.isInert);
test('bindings to disable-upgrade with false', function () {
var el = fixture('databind-not-lazy');
assert.notOk(el.$.child.hasAttribute('disable-upgrade'));
assert.equal(el.$.child.aRan, true);
assert.equal(el.$.child.cRan, true);
})
Expand Down

0 comments on commit f8f903c

Please sign in to comment.