After Ryosuke, Travis, Wilson, William, and I discussed the problem for an hour over a burrito, William came up with this approach. All hail William.
-
-
Save wilsonpage/9288711d94e73eadd018 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var shadow = host.createShadowRoot({ mode: 'closed' }); | |
// Fill the shadow-root | |
shadow.innerHTML = template; | |
// Define the distribution logic. It's important | |
// that this isn't tied to creation to make it | |
// possible for a sub-class to override | |
shadow.distribution = candidates => { | |
var points = shadow.querySelectorAll('content'); | |
candidates.forEach(candidate => { | |
for (var i = 0; i < points.length; i++) { | |
var selector = points[i].getAttribute('select'); | |
if (!selector || candidate.matches(selector)) { | |
points[i].add(candidate); | |
break; | |
} | |
}); | |
}); | |
}; | |
// Run initial distribution | |
shadow.distribute(); | |
// Attach mutation observer that invokes distribute() on childList changes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TODO |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment