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.
Last active
August 29, 2015 14:19
-
-
Save annevk/e9e61801fcfb251389ef to your computer and use it in GitHub Desktop.
Imperative Distribution
This file contains hidden or 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", | |
distribute: (distributionList, insertionList) => { | |
for(var i = 0; i < distributionList.length; i++) { | |
for(var ii = 0; ii < insertionList.length; ii++) { | |
var select = insertionList[ii].getAttribute("select") | |
if(select != null && distributionList[i].matches(select)) { | |
insertionList[ii].add(distrubtionList[i]) | |
} else if(select == null) { | |
insertionList[ii].add(distrubtionList[i]) | |
} | |
} | |
} | |
} | |
}) | |
host.shadowRoot.distribute() | |
// mutation observer code that invokes distribute() on childList changes |
This file contains hidden or 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
callback DistributionCallback = void (sequence<(Text or Element)>, sequence<HTMLContentElement>); | |
enum ShadowRootMode { "open", "closed" }; | |
dictionary ShadowRootInit { | |
require ShadowRootMode mode; | |
require DistributionCallback distribute; | |
}; | |
partial interface Element { | |
ShadowRoot createShadowRoot(ShadowRootInit options); | |
}; | |
partial interface ShadowRoot { | |
void distribute(); // invoke the callback, recursively if there's nesting | |
}; | |
interface HTMLContentElement : HTMLElement { | |
void add((Text or Element) node); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment