Skip to content

Commit

Permalink
defer all create-time preparation work if we have no defaultView unle…
Browse files Browse the repository at this point in the history
…ss forceReady flag is set. Otherwise perform this work at enteredDocument time. This is a stand in for an ownerDocumentChangedCallback.
  • Loading branch information
sorvell committed Sep 6, 2013
1 parent c440c8e commit 161d99f
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 28 deletions.
51 changes: 23 additions & 28 deletions src/instance/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 comment has been minimized.

Copy link
@netpoetica

netpoetica Oct 8, 2013

In later commits this became _elementPrepared, but I'm just curious why this boolean is being set at the beginning of a function called prepareElement? It seems intuitively that setting _elementPrepared would be the last thing that happens before leaving the context of the the prepareElement function.

Not a major deal, my main thing here is that if I had to get to the really nasty root level to debug, the last thing I would want to do is be confused by the base object right off the bat.

This comment has been minimized.

Copy link
@sjmiles

sjmiles Oct 9, 2013

Contributor

This pattern indicates that the semaphore records an attempt to perform a task (that should not be re-tried in case of error), and not successful completion of the task. In particular, the flag is set without regard to some action in this method throwing an exception.

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
Expand All @@ -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();
Expand Down
14 changes: 14 additions & 0 deletions src/instance/properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
1 change: 1 addition & 0 deletions test/html/unbind.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<script>
Polymer('x-test', {
foo: '',
forceReady: true,
ready: function() {},
fooChanged: function() {
this.fooWasChanged = true;
Expand Down
1 change: 1 addition & 0 deletions test/js/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ suite('register', function() {

test('register', function(done) {
Polymer('x-register-foo', {
forceReady: true,
ready: function() {
this.message = 'foo';
},
Expand Down

0 comments on commit 161d99f

Please sign in to comment.