Skip to content

Commit

Permalink
Add support for isInert to allow elements to boot up in an inert st…
Browse files Browse the repository at this point in the history
…ate. e.g. `<x-foo is-inert></x-foo>`. Setting `xFoo.isInert = false` causes the element to boot up.
  • Loading branch information
Steven Orvell committed Jan 31, 2017
1 parent 13f36c7 commit ca3f59d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion polymer.html
Expand Up @@ -65,7 +65,7 @@
// setup gestures
this._setupGestures();
// manage configuration
this._setupConfigure();
this._setupConfigure(this.__data__);
// setup style properties
this._setupStyleProperties();
// setup debouncers
Expand Down
37 changes: 37 additions & 0 deletions src/lib/base.html
Expand Up @@ -64,6 +64,17 @@
},

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

__initialize: function() {
if (!this.__hasRegisterFinished) {
this._ensureRegisterFinished(this.__proto__);
}
Expand Down Expand Up @@ -288,6 +299,32 @@
Polymer.Base = Polymer.Base.chainObject(Polymer.Base, HTMLElement.prototype);
Polymer.BaseDescriptors = {};

if (Polymer.Settings.enableInert) {

var inertPropertySetter = function(property, value) {
this.__data__[property] = value;
}

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;
}
}

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

if (window.CustomElements) {
Polymer.instanceof = CustomElements.instanceof;
} else {
Expand Down
3 changes: 3 additions & 0 deletions src/lib/polymer-bootstrap.html
Expand Up @@ -70,6 +70,9 @@
}

Polymer.Class = function(prototype) {
if (!prototype.factoryImpl) {
prototype.factoryImpl = function() {}
}
return desugar(prototype).constructor;
}

Expand Down

0 comments on commit ca3f59d

Please sign in to comment.