2017-12-15 14:12:44 -08:00
|
|
|
<!--
|
|
|
|
|
@license
|
|
|
|
|
Copyright (c) 2017 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
|
|
|
|
|
-->
|
2018-02-21 14:08:21 -08:00
|
|
|
<link rel="import" href="element-mixin.html">
|
2017-12-15 14:12:44 -08:00
|
|
|
<script>
|
|
|
|
|
(function() {
|
2017-12-15 14:34:07 -08:00
|
|
|
'use strict';
|
2017-12-15 14:12:44 -08:00
|
|
|
|
|
|
|
|
const DISABLED_ATTR = 'disable-upgrade';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Element class mixin that allows the element to boot up in a non-enabled
|
|
|
|
|
* state when the `disable-upgrade` attribute is present. This mixin is
|
|
|
|
|
* designed to be used with element classes like Polymer.Element that perform
|
|
|
|
|
* initial startup work when they are first connected. When the
|
|
|
|
|
* `disable-upgrade` attribute is removed, if the element is connected, it
|
|
|
|
|
* boots up and "enables" as it otherwise would; if it is not connected, the
|
|
|
|
|
* element boots up when it is next connected.
|
|
|
|
|
*
|
|
|
|
|
* Using `disable-upgrade` with Polymer.Element prevents any data propagation
|
|
|
|
|
* to the element, any element DOM from stamping, or any work done in
|
|
|
|
|
* connected/disconnctedCallback from occuring, but it does not prevent work
|
|
|
|
|
* done in the element constructor.
|
|
|
|
|
*
|
|
|
|
|
* Note, this mixin must be applied on top of any element class that
|
|
|
|
|
* itself implements a `connectedCallback` so that it can control the work
|
|
|
|
|
* done in `connectedCallback`. For example,
|
|
|
|
|
*
|
2018-02-21 12:08:19 -08:00
|
|
|
* MyClass = Polymer.DisableUpgradeMixin(class extends BaseClass {...});
|
2017-12-15 14:12:44 -08:00
|
|
|
*
|
|
|
|
|
* @mixinFunction
|
|
|
|
|
* @polymer
|
2018-02-21 12:52:00 -08:00
|
|
|
* @appliesMixin Polymer.ElementMixin
|
2017-12-15 14:12:44 -08:00
|
|
|
* @memberof Polymer
|
|
|
|
|
*/
|
2018-02-21 12:45:18 -08:00
|
|
|
Polymer.DisableUpgradeMixin = Polymer.dedupingMixin((base) => {
|
2017-12-15 14:12:44 -08:00
|
|
|
|
2018-02-21 12:45:18 -08:00
|
|
|
/**
|
|
|
|
|
* @constructor
|
|
|
|
|
* @extends {base}
|
2018-02-21 12:52:00 -08:00
|
|
|
* @implements {Polymer_ElementMixin}
|
2018-02-21 12:45:18 -08:00
|
|
|
*/
|
2018-02-21 12:52:00 -08:00
|
|
|
const superClass = Polymer.ElementMixin(base);
|
2018-02-21 12:45:18 -08:00
|
|
|
/**
|
|
|
|
|
* @polymer
|
|
|
|
|
* @mixinClass
|
|
|
|
|
* @implements {Polymer_DisableUpgradeMixin}
|
|
|
|
|
*/
|
|
|
|
|
class DisableUpgradeClass extends superClass {
|
2017-12-15 14:12:44 -08:00
|
|
|
|
2018-02-21 12:45:18 -08:00
|
|
|
/** @override */
|
2017-12-15 14:12:44 -08:00
|
|
|
static get observedAttributes() {
|
|
|
|
|
return super.observedAttributes.concat(DISABLED_ATTR);
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-21 12:45:18 -08:00
|
|
|
/** @override */
|
2018-03-30 15:33:39 -07:00
|
|
|
attributeChangedCallback(name, old, value, namespace) {
|
2017-12-15 14:12:44 -08:00
|
|
|
if (name == DISABLED_ATTR) {
|
|
|
|
|
if (!this.__dataEnabled && value == null && this.isConnected) {
|
|
|
|
|
super.connectedCallback();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2018-03-30 15:33:39 -07:00
|
|
|
super.attributeChangedCallback(name, old, value, namespace);
|
2017-12-15 14:12:44 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-09 16:46:17 -08:00
|
|
|
/*
|
|
|
|
|
NOTE: cannot gate on attribute because this is called before
|
|
|
|
|
attributes are delivered. Therefore, we stub this out and
|
|
|
|
|
call `super._initializeProperties()` manually.
|
|
|
|
|
*/
|
2018-02-21 12:45:18 -08:00
|
|
|
/** @override */
|
2018-01-09 16:46:17 -08:00
|
|
|
_initializeProperties() {}
|
2017-12-15 14:12:44 -08:00
|
|
|
|
|
|
|
|
// prevent user code in connected from running
|
2018-02-21 12:45:18 -08:00
|
|
|
/** @override */
|
2017-12-15 14:12:44 -08:00
|
|
|
connectedCallback() {
|
2018-01-09 16:46:17 -08:00
|
|
|
if (this.__dataEnabled || !this.hasAttribute(DISABLED_ATTR)) {
|
2017-12-15 14:12:44 -08:00
|
|
|
super.connectedCallback();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// prevent element from turning on properties
|
2018-02-21 12:45:18 -08:00
|
|
|
/** @override */
|
2017-12-15 14:12:44 -08:00
|
|
|
_enableProperties() {
|
2018-01-09 16:46:17 -08:00
|
|
|
if (!this.hasAttribute(DISABLED_ATTR)) {
|
|
|
|
|
if (!this.__dataEnabled) {
|
|
|
|
|
super._initializeProperties();
|
|
|
|
|
}
|
2017-12-15 14:12:44 -08:00
|
|
|
super._enableProperties();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// only go if "enabled"
|
2018-02-21 12:45:18 -08:00
|
|
|
/** @override */
|
2017-12-15 14:12:44 -08:00
|
|
|
disconnectedCallback() {
|
|
|
|
|
if (this.__dataEnabled) {
|
|
|
|
|
super.disconnectedCallback();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-21 12:45:18 -08:00
|
|
|
}
|
2017-12-15 14:34:07 -08:00
|
|
|
|
2018-02-21 12:45:18 -08:00
|
|
|
return DisableUpgradeClass;
|
|
|
|
|
|
|
|
|
|
});
|
2017-12-15 14:12:44 -08:00
|
|
|
|
|
|
|
|
})();
|
|
|
|
|
|
2018-03-30 15:33:39 -07:00
|
|
|
</script>
|