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

Commit

Permalink
fix: Fix deferred shadow roots by lazily getting the shadow root when…
Browse files Browse the repository at this point in the history
… needed.
  • Loading branch information
treshugart committed Nov 28, 2016
1 parent 9c695b4 commit 502b279
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,25 +84,28 @@ class Wrapper {
fixture.appendChild(node);
customElementDefinition && flush();
}
}

// If there's no shadow root, our queries run from the host.
this.shadowRoot = node.shadowRoot || node;
get shadowRoot () {
const { node } = this;
return node.shadowRoot || node;
}

all (query) {
const { shadowRoot } = this;
let temp = [];

// Custom element constructors
if (query.prototype instanceof HTMLElement) {
this.walk(
this.shadowRoot,
shadowRoot,
node => node instanceof query,
node => temp.push(node)
);
// Custom filtering function
} else if (typeof query === 'function') {
this.walk(
this.shadowRoot,
shadowRoot,
query,
node => temp.push(node)
);
Expand All @@ -113,7 +116,7 @@ class Wrapper {
// chain lookup.
} else if (query.nodeType === Node.ELEMENT_NODE) {
this.walk(
this.shadowRoot,
shadowRoot,
node => diff({ destination: query, source: node, root: true }).length === 0,
node => temp.push(node)
);
Expand All @@ -124,14 +127,14 @@ class Wrapper {
return temp;
}
this.walk(
this.shadowRoot,
shadowRoot,
node => keys.every(key => node[key] === query[key]),
node => temp.push(node)
);
// Selector
} else if (typeof query === 'string') {
this.walk(
this.shadowRoot,
shadowRoot,
node => matches(node, query),
node => temp.push(node),
{ skip: true }
Expand Down

0 comments on commit 502b279

Please sign in to comment.