Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Commit

Permalink
Update & pass child-accessing test
Browse files Browse the repository at this point in the history
  • Loading branch information
gilbert committed Nov 15, 2016
1 parent 3f7c02e commit 374b24f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
17 changes: 8 additions & 9 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,9 @@ function transformTree(document, visitedNodes, currentNode, callback) {

visitedNodes.add(currentNode);

let visitChildren = () => Promise.all(
map(currentNode.childNodes, (child) => transformTree(document, visitedNodes, child, callback))
);

return Promise.resolve(task).then(visitChildren);
for (var child of currentNode.childNodes) {
transformTree(document, visitedNodes, child, callback);
}
}

/**
Expand Down Expand Up @@ -88,7 +86,7 @@ function renderNode(rootNode) {
var visitedNodes = new Set();
var customElements = exports.customElements;

return transformTree(document, visitedNodes, rootNode, function render (element) {
transformTree(document, visitedNodes, rootNode, function render (element) {

const definition = customElements.getDefinition(element.localName);

Expand All @@ -99,13 +97,14 @@ function renderNode(rootNode) {
upgradeElement(element, definition, true);

if (definition.connectedCallback) {
return new Promise(function(resolve, reject) {
var p = new Promise(function(resolve, reject) {
resolve( definition.connectedCallback.call(element, document) );
});
createdPromises.push(p);
}
}
})
.then(() => rootNode);
});
return Promise.all(createdPromises).then(function(){ return rootNode; });
}

/**
Expand Down
15 changes: 10 additions & 5 deletions test/multiple-element-interactions-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,19 @@ describe("When multiple DOM elements are present", () => {
});
});

// Pending until we decide on a good solution
xit("can read attributes from custom child element's prototypes", () => {
it("can read attributes from custom child element's prototypes", () => {
class DataSource extends customElements.HTMLElement {
get data() {
return [10, 20, 30];
}
}
customElements.define("data-source", DataSource);

class DataDisplayer extends customElements.HTMLElement {
connectedCallback() {
return new Promise((resolve) => {
// Has to be async, as child node prototypes aren't set: http://stackoverflow.com/questions/36187227/
// This is a web customElements limitation generally. TODO: Find a nicer pattern for handle this.
// This is a web components limitation generally. TODO: Find a nicer pattern for handle this.
setTimeout(() => {
var data = this.childNodes[0].data;
this.textContent = "Data: " + JSON.stringify(data);
Expand All @@ -62,9 +68,8 @@ describe("When multiple DOM elements are present", () => {
});
}
}
DataSource.data = [10, 20, 30];

customElements.define("data-displayer", DataSource);
customElements.define("data-displayer", DataDisplayer);

return customElements.renderFragment(
"<data-displayer><data-source></data-source></data-displayer>"
Expand Down

0 comments on commit 374b24f

Please sign in to comment.