Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure detached cannot be called when disble-upgrade is set #4607

Merged
merged 3 commits into from
May 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/mini/ready.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
(function() {

var baseAttachedCallback = Polymer.Base.attachedCallback;
var baseDetachedCallback = Polymer.Base.detachedCallback;

Polymer.Base._addFeature({

Expand Down Expand Up @@ -175,6 +176,23 @@
} else {
this._attachedPending = true;
}
},

/**
* Polymer library implementation of the Custom Elements `detachedCallback`.
*
* Note, users should not override `detachedCallback`, and instead should
* implement the `detached` method on Polymer elements to receive
* detached-time callbacks.
*
* @protected
*/
detachedCallback: function() {
if (this._readied) {
baseDetachedCallback.call(this);
} else {
this._attachedPending = false;
}
}

});
Expand Down
85 changes: 85 additions & 0 deletions test/unit/element-disable-upgrade.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,44 @@
</script>
</dom-module>

<dom-module id="x-attach">
<template>
<style>
:host {
display: block;
}
</style>
<div id="child">Live!</div>
</template>
<script>
HTMLImports.whenReady(function() {
Polymer({
is: 'x-attach',
attached: function() {
this._connectLog = this._connectLog || [];
this._connectLog.push('attached');
},
detached: function() {
this._connectLog = this._connectLog || [];
this._connectLog.push('detached');
}
});
});
</script>
</dom-module>

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

<test-fixture id="attach">
<template>
<x-attach disable-upgrade></x-attach>
</template>
</test-fixture>

<dom-module id="x-complicated-child">
<script>
HTMLImports.whenReady(function() {
Expand Down Expand Up @@ -141,6 +173,59 @@
assert.ok(el.$.child);
});
});
suite('disableUpgrade attach/detach', function() {
var el;
setup(function() {
el = fixture('attach');
});
test('attached does not fire when element is not yet enabled', function() {
assert.notOk(el._connectLog);
el.removeAttribute('disable-upgrade');
assert.equal(el._connectLog.length, 1);
assert.equal(el._connectLog[0], 'attached');
});
test('attached/detached do not fire when element is not yet enabled', function() {
el.parentNode.removeChild(el);
Polymer.dom.flush();
assert.notOk(el._connectLog);
el.removeAttribute('disable-upgrade');
assert.notOk(el._connectLog);
});
test('attached/detached do not fire when element is detached/attached when not yet enabled', function() {
var parent = el.parentNode;
parent.removeChild(el);
Polymer.dom.flush();
assert.notOk(el._connectLog);
parent.appendChild(el);
Polymer.dom.flush();
assert.notOk(el._connectLog);
assert.notOk(el._connectLog);
el.removeAttribute('disable-upgrade');
assert.equal(el._connectLog.length, 1);
assert.equal(el._connectLog[0], 'attached');
});

test('attached/detached fire as expected after element is enabled', function() {
var parent = el.parentNode;
parent.removeChild(el);
Polymer.dom.flush();
assert.notOk(el._connectLog);
parent.appendChild(el);
Polymer.dom.flush();
assert.notOk(el._connectLog);
el.removeAttribute('disable-upgrade');
assert.equal(el._connectLog.length, 1);
assert.equal(el._connectLog[0], 'attached');
parent.removeChild(el);
Polymer.dom.flush();
assert.equal(el._connectLog.length, 2);
assert.equal(el._connectLog[1], 'detached');
parent.appendChild(el);
Polymer.dom.flush();
assert.equal(el._connectLog.length, 3);
assert.equal(el._connectLog[2], 'attached');
});
});
suite('disableUpgrade and Databinding', function() {
test('binding to disable-upgrade with true', function() {
var el = fixture('databind-lazy');
Expand Down