Steve Orvell
2015-03-13 20:15:37 -07:00
parent bb7a21c95a
commit a0f51e6cda
8 changed files with 67 additions and 40 deletions

View File

@@ -79,12 +79,11 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
return !this._readied && (!this.host || this.host._readied);
},
// TODO(sorvell): can this be collapsed with _distributeContent?
_initializeContent: function() {
// prepare root
this._setupRoot();
// logically distribute self
this._prepareContent();
this._beginDistribute();
// send data configuration signal
this._configure();
// now fully prepare localChildren
@@ -93,7 +92,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
c._initializeContent();
}
// perform actual dom composition
this._composeContent();
this._finishDistribute();
// send ready signal
this._ready();
},

View File

@@ -22,16 +22,19 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
// no-op's when ShadowDOM is in use
_poolContent: function() {},
_prepareContent: function() {},
_composeTree: function() {},
distributeContent: function() {},
_beginDistribute: function() {},
_distributeContent: function() {},
// create a shadowRoot
_createLocalRoot: function() {
// native ShadowDOM method
this.createShadowRoot();
this.shadowRoot.appendChild(this.root);
this.root = this.shadowRoot;
},
_finishDistribute: function() {
if (this.shadowRoot && (this.root !== this.shadowRoot)) {
this.shadowRoot.appendChild(this.root);
this.root = this.shadowRoot;
}
}
});

View File

@@ -49,7 +49,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
_distributeContent: function() {
// logically distribute self
if (!this._distributionClean) {
this._prepareContent();
this._beginDistribute();
}
// TODO(sorvell): consider having a 'dirtyList' of elements to distribute
// now fully distribute/compose "clients"
@@ -61,11 +61,11 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
}
}
if (!this._distributionClean) {
this._composeContent();
this._finishDistribute();
}
},
_prepareContent: function() {
_beginDistribute: function() {
if (this._useContent) {
// reset distributions
this._resetDistribution(this.shadyRoot);
@@ -76,7 +76,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
}
},
_composeContent: function() {
_finishDistribute: function() {
// compose self
if (this._useContent) {
this._composeTree(this);

View File

@@ -22,6 +22,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
'unit/async.html',
'unit/template.html',
'unit/ready.html',
'unit/ready-shadow.html',
'unit/configure.html',
'unit/shady.html',
'unit/projection.html',

View File

@@ -1,7 +1,7 @@
<script>
var configureList = [];
var readyList = [];
function clearTestLists() {
configureList = [];
readyList = [];
@@ -13,6 +13,7 @@
},
// use private, stateful, method for testing purposes
_configure: function() {
assert.isTrue(!this.isAttached, 'Element should not be attached when configured.');
configureList.push(this.moniker());
},
ready: function() {
@@ -20,13 +21,13 @@
},
attached: function() {
assert.isTrue(this._readied, 'Element not ready when iserted');
assert.isTrue(this._readied, 'Element not ready when attached');
}
};
</script>
<template>
x-zot
x-zot<content></content>
</template>
<script>
Polymer({

View File

@@ -0,0 +1,26 @@
<!doctype html>
<!--
@license
Copyright (c) 2014 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
-->
<html>
<head>
<meta charset="utf-8">
<script src="../../../webcomponentsjs/webcomponents.js"></script>
<script src="../../../web-component-tester/browser.js"></script>
<script> Polymer={dom: 'shadow'} </script>
<link rel="import" href="../../polymer.html">
<link rel="import" href="ready-elements.html">
</head>
<body>
<x-ready></x-ready>
<script src="ready.js"></script>
</body>
</html>

View File

@@ -20,28 +20,6 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
<x-ready></x-ready>
<script>
suite('ready', function() {
var configure = ['x-ready', 'x-zot#a', 'x-zot#b', 'x-zot#c', 'x-zot#d', 'x-foo', 'x-bar', 'x-zot', 'x-bar', 'x-zot'];
var ready = ['x-zot#a', 'x-zot#b', 'x-zot#c', 'x-zot#d', 'x-zot', 'x-bar', 'x-zot', 'x-bar', 'x-foo', 'x-ready'];
test('element create in dom calls configure/ready in proper order', function() {
assert.deepEqual(configureList, configure);
assert.deepEqual(readyList, ready);
});
test('element create + attach calls configure/ready in proper order', function() {
clearTestLists();
document.body.appendChild(document.createElement('x-ready'));
CustomElements.takeRecords(document);
assert.deepEqual(configureList, configure);
assert.deepEqual(readyList, ready);
});
});
</script>
<script src="ready.js"></script>
</body>
</html>

19
test/unit/ready.js Normal file
View File

@@ -0,0 +1,19 @@
suite('ready', function() {
var configure = ['x-ready', 'x-zot#a', 'x-zot#b', 'x-zot#c', 'x-zot#d', 'x-foo', 'x-bar', 'x-zot', 'x-bar', 'x-zot'];
var ready = ['x-zot#a', 'x-zot#b', 'x-zot#c', 'x-zot#d', 'x-zot', 'x-bar', 'x-zot', 'x-bar', 'x-foo', 'x-ready'];
test('element create in dom calls configure/ready/attached in proper order', function() {
assert.deepEqual(configureList, configure);
assert.deepEqual(readyList, ready);
});
test('element create + attach calls configure/ready/attached in proper order', function() {
clearTestLists();
document.body.appendChild(document.createElement('x-ready'));
CustomElements.takeRecords(document);
assert.deepEqual(configureList, configure);
assert.deepEqual(readyList, ready);
});
});