diff --git a/src/instance/base.js b/src/instance/base.js index 5ee15a26cf..f17f185ff8 100644 --- a/src/instance/base.js +++ b/src/instance/base.js @@ -15,28 +15,36 @@ // TODO(sorvell): temporary BC ready: function() { - }, - // TODO(sjmiles): temporary BC - readyCallback: function() { - this._createdCallback(); }, createdCallback: function() { - this._createdCallback(); + if (this.ownerDocument.defaultView || this.forceReady || + Polymer.preparingElements) { + this.prepare(); + } }, // system entry point, do not override - _createdCallback: function() { + prepare: function() { + if (this._prepared) { + return; + } + this._prepared = true; //this.style.display = 'inline-block'; // install property observers - // do this first so we can observe changes during initialization - this.observeProperties(); // install boilerplate attributes this.copyInstanceAttributes(); // process input attributes this.takeAttributes(); + // do this first so we can observe changes during initialization + //this.observeProperties(); // add event listeners this.addHostListeners(); + // forces sub-elements to be prepared + Polymer.preparingElements = true; // process declarative resources this.parseElements(this.__proto__); + Polymer.preparingElements = false; + this.observeProperties(); + //Platform.endOfMicrotask(this.initializeProperties.bind(this)); // unless this element is inserted into the main document // (or the user otherwise specifically prevents it) // bindings will self destruct after a short time; this is @@ -45,38 +53,25 @@ //this.asyncUnbindAll(); // user initialization // TODO(sorvell): bc + //console.log('created', this); this.ready(); this.created(); - }, - insertedCallback: function() { - this._enteredDocumentCallback(); + // TODO(sorvell): refactor so this doesn't depend on properties already + // having been observed + this.initializeProperties(); }, enteredDocumentCallback: function() { - this._enteredDocumentCallback(); - }, - _enteredDocumentCallback: function() { - this.cancelUnbindAll(true); - // TODO(sorvell): bc - if (this.inserted) { - this.inserted(); + if (!this.forceReady) { + this.prepare(); } + this.cancelUnbindAll(true); // invoke user action if (this.enteredDocument) { this.enteredDocument(); } }, - removedCallback: function() { - this._leftDocumentCallback(); - }, leftDocumentCallback: function() { - this._leftDocumentCallback(); - }, - _leftDocumentCallback: function() { this.asyncUnbindAll(); - // TODO(sorvell): bc - if (this.removed) { - this.removed(); - } // invoke user action if (this.leftDocument) { this.leftDocument(); diff --git a/src/instance/properties.js b/src/instance/properties.js index 6f645d45a1..93c38bad5a 100644 --- a/src/instance/properties.js +++ b/src/instance/properties.js @@ -27,6 +27,20 @@ this.observeProperty(n); } }, + // TODO(sorvell): refactor so this doesn't depend on properties already + // having been observed + initializeProperties: function() { + var $o = Object.keys(getElementObservers(this)); + for (var i=0; i < $o.length; i++) { + this.initializeProperty($o[i]) + } + }, + initializeProperty: function(name) { + var neo = this[name], old = this.__proto__[name] + if (neo !== old) { + this.dispatchPropertyChange(name, old); + } + }, // fetch an pre-constructor array of all property names in our prototype // chain above PolymerBase getCustomPropertyNames: function() { diff --git a/test/html/unbind.html b/test/html/unbind.html index 3870e9e734..4e4a61e937 100644 --- a/test/html/unbind.html +++ b/test/html/unbind.html @@ -16,6 +16,7 @@