Skip to content

Commit 161d99f

Browse files
committed
defer all create-time preparation work if we have no defaultView unless forceReady flag is set. Otherwise perform this work at enteredDocument time. This is a stand in for an ownerDocumentChangedCallback.
1 parent c440c8e commit 161d99f

File tree

4 files changed

+39
-28
lines changed

4 files changed

+39
-28
lines changed

src/instance/base.js

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,36 @@
1515
// TODO(sorvell): temporary BC
1616
ready: function() {
1717

18-
},
19-
// TODO(sjmiles): temporary BC
20-
readyCallback: function() {
21-
this._createdCallback();
2218
},
2319
createdCallback: function() {
24-
this._createdCallback();
20+
if (this.ownerDocument.defaultView || this.forceReady ||
21+
Polymer.preparingElements) {
22+
this.prepare();
23+
}
2524
},
2625
// system entry point, do not override
27-
_createdCallback: function() {
26+
prepare: function() {
27+
if (this._prepared) {
28+
return;
29+
}
30+
this._prepared = true;
2831
//this.style.display = 'inline-block';
2932
// install property observers
30-
// do this first so we can observe changes during initialization
31-
this.observeProperties();
3233
// install boilerplate attributes
3334
this.copyInstanceAttributes();
3435
// process input attributes
3536
this.takeAttributes();
37+
// do this first so we can observe changes during initialization
38+
//this.observeProperties();
3639
// add event listeners
3740
this.addHostListeners();
41+
// forces sub-elements to be prepared
42+
Polymer.preparingElements = true;
3843
// process declarative resources
3944
this.parseElements(this.__proto__);
45+
Polymer.preparingElements = false;
46+
this.observeProperties();
47+
//Platform.endOfMicrotask(this.initializeProperties.bind(this));
4048
// unless this element is inserted into the main document
4149
// (or the user otherwise specifically prevents it)
4250
// bindings will self destruct after a short time; this is
@@ -45,38 +53,25 @@
4553
//this.asyncUnbindAll();
4654
// user initialization
4755
// TODO(sorvell): bc
56+
//console.log('created', this);
4857
this.ready();
4958
this.created();
50-
},
51-
insertedCallback: function() {
52-
this._enteredDocumentCallback();
59+
// TODO(sorvell): refactor so this doesn't depend on properties already
60+
// having been observed
61+
this.initializeProperties();
5362
},
5463
enteredDocumentCallback: function() {
55-
this._enteredDocumentCallback();
56-
},
57-
_enteredDocumentCallback: function() {
58-
this.cancelUnbindAll(true);
59-
// TODO(sorvell): bc
60-
if (this.inserted) {
61-
this.inserted();
64+
if (!this.forceReady) {
65+
this.prepare();
6266
}
67+
this.cancelUnbindAll(true);
6368
// invoke user action
6469
if (this.enteredDocument) {
6570
this.enteredDocument();
6671
}
6772
},
68-
removedCallback: function() {
69-
this._leftDocumentCallback();
70-
},
7173
leftDocumentCallback: function() {
72-
this._leftDocumentCallback();
73-
},
74-
_leftDocumentCallback: function() {
7574
this.asyncUnbindAll();
76-
// TODO(sorvell): bc
77-
if (this.removed) {
78-
this.removed();
79-
}
8075
// invoke user action
8176
if (this.leftDocument) {
8277
this.leftDocument();

src/instance/properties.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,20 @@
2727
this.observeProperty(n);
2828
}
2929
},
30+
// TODO(sorvell): refactor so this doesn't depend on properties already
31+
// having been observed
32+
initializeProperties: function() {
33+
var $o = Object.keys(getElementObservers(this));
34+
for (var i=0; i < $o.length; i++) {
35+
this.initializeProperty($o[i])
36+
}
37+
},
38+
initializeProperty: function(name) {
39+
var neo = this[name], old = this.__proto__[name]
40+
if (neo !== old) {
41+
this.dispatchPropertyChange(name, old);
42+
}
43+
},
3044
// fetch an pre-constructor array of all property names in our prototype
3145
// chain above PolymerBase
3246
getCustomPropertyNames: function() {

test/html/unbind.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
<script>
1717
Polymer('x-test', {
1818
foo: '',
19+
forceReady: true,
1920
ready: function() {},
2021
fooChanged: function() {
2122
this.fooWasChanged = true;

test/js/register.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ suite('register', function() {
2020

2121
test('register', function(done) {
2222
Polymer('x-register-foo', {
23+
forceReady: true,
2324
ready: function() {
2425
this.message = 'foo';
2526
},

0 commit comments

Comments
 (0)