<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.whatwg.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Arv</id>
	<title>WHATWG Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.whatwg.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Arv"/>
	<link rel="alternate" type="text/html" href="https://wiki.whatwg.org/wiki/Special:Contributions/Arv"/>
	<updated>2026-05-10T15:00:55Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.39.3</generator>
	<entry>
		<id>https://wiki.whatwg.org/index.php?title=Component_Model_Use_Cases&amp;diff=5731</id>
		<title>Component Model Use Cases</title>
		<link rel="alternate" type="text/html" href="https://wiki.whatwg.org/index.php?title=Component_Model_Use_Cases&amp;diff=5731"/>
		<updated>2011-01-05T17:50:03Z</updated>

		<summary type="html">&lt;p&gt;Arv: Removed duplicate link to GWT&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;A canonical set of uses cases that represents the set of problems we are trying to solve by implementing a component model. For implementation details, see [http://dev.w3.org/2006/xbl2/Overview.html XBL2 Spec].&lt;br /&gt;
&lt;br /&gt;
This document is broken out into two sections: &#039;&#039;&#039;general use cases&#039;&#039;&#039; provide insight into how the component model could be used; &#039;&#039;&#039;specific use cases&#039;&#039;&#039; are interesting scenarios within the general use cases that should be treated as constraints/requirements, imposed on the specification/implementation of the component model.&lt;br /&gt;
&lt;br /&gt;
=General Use Cases=&lt;br /&gt;
&lt;br /&gt;
==Built-in HTML Elements==&lt;br /&gt;
&lt;br /&gt;
Many non-trivial (i.e. with additional behavior and styling beyond the standard box model) elements that exist in HTML today could be implemented using HTML/CSS/JS. [https://wiki.mozilla.org/Gecko:Home_Page Gecko] already takes this approach pretty far. It makes sense to provide a standardized way to accomplish this, with the short-term goals of reducing the size of browsers C++ code and making new element implementation easier, and the long-term goal of converging built-in HTML element implementations across browsers.&lt;br /&gt;
&lt;br /&gt;
Requirements:&lt;br /&gt;
* provide a uniform way to browsers to implement complex HTML elements, such as video/audio, sliders, progress elements, etc. possibly using scripting.&lt;br /&gt;
&lt;br /&gt;
Needs:&lt;br /&gt;
* UA-level attachment&lt;br /&gt;
* ability to designate and use DOM SPIs only within the shadow scope&lt;br /&gt;
* ability to completely hide implementation details from author and user&lt;br /&gt;
* restricted post-UA-level styling using pseudoclasses&lt;br /&gt;
* style/event propagation control at the borders of the shadow DOM&lt;br /&gt;
* high performance, especially compared to native implementation&lt;br /&gt;
&lt;br /&gt;
Could use:&lt;br /&gt;
* declarative templating/binding&lt;br /&gt;
&lt;br /&gt;
Doesn&#039;t care:&lt;br /&gt;
* mutable templates&lt;br /&gt;
* dynamic attachment/detachment&lt;br /&gt;
* template inheritance&lt;br /&gt;
* attachment using CSS or DOM&lt;br /&gt;
* content element (output ports), since they can&#039;t have children (this may change)&lt;br /&gt;
* attribute/pseudo forwarding&lt;br /&gt;
* xml:base handling&lt;br /&gt;
&lt;br /&gt;
Interesting scenarios:&lt;br /&gt;
* Implement a video/audio element. How can the binding reach into a private supporting API that is not available to the author?&lt;br /&gt;
&lt;br /&gt;
== Custom Widget System ==&lt;br /&gt;
&lt;br /&gt;
As it is today (Jan 1, 2011), pretty much every Javascript framework has a widget system (see http://jqueryui.com/, http://sproutcore.com/, http://o.dojotoolkit.org/projects/dijit, http://cappuccino.org/, http://code.google.com/webtoolkit/, http://code.google.com/closure/library/, http://www.sencha.com/ as just a few examples).  All of these these widget systems are framework-specific and mostly incompatible with each other. &lt;br /&gt;
Because the Web platform doesn&#039;t provide a well-functioning way to extend HTML elements, all of these tend to build a parallel widget space, where widget objects act as proxies to DOM objects, and the extensibility exists only within that parallel widget space. A DOM-based component model should aim to eliminate the need for this parallel space and allow widget systems to just use DOM with the goals of:&lt;br /&gt;
* reducing the amount of widget-space-related code written in each framework&lt;br /&gt;
* providing better, leak-free abstraction for widgets&lt;br /&gt;
* providing interoperable API to allow widgets from different frameworks to coexist and integrate.&lt;br /&gt;
&lt;br /&gt;
Requirements:&lt;br /&gt;
* provide a uniform way (i.e. DOM) to declare widget APIs&lt;br /&gt;
* encapsulate widget implementation details&lt;br /&gt;
* enable control over how styles and events outside of a widget affect it&lt;br /&gt;
* enable widget styling primitives&lt;br /&gt;
* asynchronously instantiate and initialize widgets (for instance, display a widget without starting up a script context, then progressively enhance with script).&lt;br /&gt;
* allow seamless reuse a widget written using various libraries or frameworks&lt;br /&gt;
* allow using widgets declaratively, with minimal knowledge of the underlying implementation&lt;br /&gt;
* provide a way to create new widgets by extending existing widgets&lt;br /&gt;
&lt;br /&gt;
Needs:&lt;br /&gt;
* shadow DOM&lt;br /&gt;
* content element (output ports)&lt;br /&gt;
* style/event propagation control at the borders of the shadow DOM&lt;br /&gt;
* attachment using CSS and DOM&lt;br /&gt;
* separate instantiation and binding phases (or another way to allow asynchronous binding)&lt;br /&gt;
* attribute/pseudo forwarding&lt;br /&gt;
* declarative templating/binding&lt;br /&gt;
&lt;br /&gt;
Could use:&lt;br /&gt;
* dynamic attachment/detachment&lt;br /&gt;
* template inheritance&lt;br /&gt;
&lt;br /&gt;
Doesn&#039;t care:&lt;br /&gt;
* mutable templates&lt;br /&gt;
* xml:base handling&lt;br /&gt;
&lt;br /&gt;
Interesting scenarios:&lt;br /&gt;
* Implement a &amp;quot;polaroid frame&amp;quot; widget? This widget, when bound to any element would display its contents in a Polaroid(tm)-like frame.&lt;br /&gt;
* Suppose the widget system has a centralized &amp;quot;settings&amp;quot; widget, with which all other widgets should communicate to add their settings. Implement this communication, provided that all widgets are opaque elements.&lt;br /&gt;
* Implement a &amp;quot;tab set&amp;quot; widget. As you add &amp;quot;tabs&amp;quot; to it, tab titles appear in a row at the top, and tab contents appear in the main area, only visible when the corresponding tab title is selected.&lt;br /&gt;
&lt;br /&gt;
==Layout Manager==&lt;br /&gt;
&lt;br /&gt;
Does:&lt;br /&gt;
* provide a framework for client-side restructuring of content to accommodate layout&lt;br /&gt;
* support both imperative a declarative layout models&lt;br /&gt;
* provide templating/theming capabilities&lt;br /&gt;
&lt;br /&gt;
Needs:&lt;br /&gt;
* shadow DOM&lt;br /&gt;
* content element (output ports)&lt;br /&gt;
* attachment using CSS and DOM&lt;br /&gt;
* separate instantiation and binding phases (or another way to allow asynchronous binding)&lt;br /&gt;
&lt;br /&gt;
Could use:&lt;br /&gt;
&lt;br /&gt;
Doesn&#039;t care:&lt;br /&gt;
* mutable templates&lt;br /&gt;
* xml:base handling&lt;br /&gt;
&lt;br /&gt;
==Specialized Markup Languages==&lt;br /&gt;
&lt;br /&gt;
It&#039;s possible to imagine the component model to be used for lightweight implementations of specialized markup languages, such as MathML. &lt;br /&gt;
&#039;&#039;&#039;This section needs work.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=Specific Use Cases=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Shadow DOM==&lt;br /&gt;
A component model should allow a component to hide its implementation details from the consumer. For instance, consider this bit of code:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;input type=&amp;quot;range&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The least thing the user of this element would expect is being able to walk down the DOM subtree of the &amp;lt;code&amp;gt;input&amp;lt;/code&amp;gt; element and find the thumb element inside:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;input type=&amp;quot;range&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;div&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/input&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Similarly, that&#039;s not what the code managing the range slider would want to happen. Thus, the &#039;&#039;&#039;shadow DOM&#039;&#039;&#039; is &#039;&#039;a way to provide a DOM subtree that is rendered as part of the document, but is not accessible by traversing the document tree&#039;&#039;. Shadow DOM provides the necessary level of isolation between component and non-component parts of the DOM tree and is the fundamental part of the component model.&lt;br /&gt;
&lt;br /&gt;
==Dynamic Binding Mechanism==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Multiple Shadow DOM Subtrees==&lt;br /&gt;
A new component might want to build upon an existing component to provide new functionality. For example, I might want to turn the &amp;lt;code&amp;gt;input type=&amp;quot;range&amp;quot;&amp;lt;/code&amp;gt; into a dial, rather than a slider. The dial code is implemented as a shadow DOM subtree and is bound to the element like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/* CSS */&lt;br /&gt;
input[type=&#039;range&#039;].dial {&lt;br /&gt;
    binding: url(http://example.com/dial/);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To use my dial, I have this bit of code:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function setDialMode(id, dial)&lt;br /&gt;
{&lt;br /&gt;
    var input = document.getElementById(id);&lt;br /&gt;
    if (dial)&lt;br /&gt;
      input.classList.add(&#039;dial&#039;);&lt;br /&gt;
    else&lt;br /&gt;
      input.classList.remove(&#039;dial&#039;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The user&#039;s expectations is that the &amp;lt;code&amp;gt;input&amp;lt;/code&amp;gt; element turns into a dial once the &amp;lt;code&amp;gt;dial&amp;lt;/code&amp;gt; class is set and reverts back to the slider once it&#039;s removed. Given that slider itself is implemented as a shadow DOM subtree,  this indicates that multiple shadow DOM subtrees could exist on an element at the same time with only one subtree rendered.&lt;br /&gt;
&lt;br /&gt;
==Tens of Thousands of Widgets==&lt;br /&gt;
The implementation should be able to efficiently handle a very large number of instances from the same template (see [http://lists.w3.org/Archives/Public/public-webapps/2010OctDec/0979.html discussion]).&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
&amp;lt;head&amp;gt;&lt;br /&gt;
    &amp;lt;binding element=&amp;quot;div&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;style scoped&amp;gt;&lt;br /&gt;
            div.pretty {&lt;br /&gt;
                background-color: Pretty;&lt;br /&gt;
            }&lt;br /&gt;
        &amp;lt;/style&amp;gt;&lt;br /&gt;
        &amp;lt;template&amp;gt;&lt;br /&gt;
            &amp;lt;div class=&amp;quot;pretty&amp;quot;&amp;gt;Pretty is, pretty does.&amp;lt;/div&amp;gt;&lt;br /&gt;
        &amp;lt;/template&amp;gt;&lt;br /&gt;
    &amp;lt;/binding&amp;gt;&lt;br /&gt;
&amp;lt;/head&amp;gt;&lt;br /&gt;
&amp;lt;body&amp;gt;&lt;br /&gt;
    &amp;lt;script&amp;gt;&lt;br /&gt;
        for(var i = 0; i &amp;lt; 20 * 1000; ++i)&lt;br /&gt;
            document.body.appendChild(document.createElement(&#039;div&#039;));&lt;br /&gt;
    &amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Insertion Points, Not Containers==&lt;br /&gt;
Output ports need to be insertion points, not cointainers. If the output port is a container (that is, an existing element in the shadow subtree is designated as a place to add the &amp;quot;light&amp;quot; nodes), some layout scenarios aren&#039;t possible. In this example, you can not use flexbox to layout all of the paragraphs in the story:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;template&amp;gt;&lt;br /&gt;
    &amp;lt;p&amp;gt;Once upon a time,&lt;br /&gt;
    &amp;lt;content includes=&amp;quot;p&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;p&amp;gt;And they lived happily ever after&lt;br /&gt;
&amp;lt;/template&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
It is useful to think of the output port as a [https://developer.mozilla.org/en/DOM:range.collapsed collapsed range].&lt;br /&gt;
&lt;br /&gt;
==Shadow Subtree Mutation==&lt;br /&gt;
Because content element is an insertion point, what happens when the elements around it change? What happens when the insertion point moves?&lt;br /&gt;
* &#039;&#039;&#039;Modifying includes attribute&#039;&#039;&#039;. What happens when you modify the &amp;lt;code&amp;gt;includes&amp;lt;/code&amp;gt; element on the output port? &lt;br /&gt;
* &#039;&#039;&#039;Nested shadow subtrees&#039;&#039;&#039;. Suppose you have two bindings, one applied inside another:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
&amp;lt;head&amp;gt;&lt;br /&gt;
    &amp;lt;binding element=&amp;quot;div#foo&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;template&amp;gt;&lt;br /&gt;
            &amp;lt;span&amp;gt;&lt;br /&gt;
                &amp;lt;content&amp;gt;&amp;lt;/content&amp;gt;&lt;br /&gt;
            &amp;lt;/span&amp;gt;&lt;br /&gt;
        &amp;lt;/template&amp;gt;&lt;br /&gt;
    &amp;lt;/binding&amp;gt;&lt;br /&gt;
    &amp;lt;binding element=&amp;quot;div#bar&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;template&amp;gt;&lt;br /&gt;
            &amp;lt;div&amp;gt;&lt;br /&gt;
                &amp;lt;div id=&amp;quot;foo&amp;quot;&amp;gt;&lt;br /&gt;
                    &amp;lt;span&amp;gt;Blah&amp;lt;/span&amp;gt;&lt;br /&gt;
                    &amp;lt;content&amp;gt;&amp;lt;/content&amp;gt;&lt;br /&gt;
                &amp;lt;/div&amp;gt;&lt;br /&gt;
        &amp;lt;/template&amp;gt;&lt;br /&gt;
    &amp;lt;/binding&amp;gt;&lt;br /&gt;
&amp;lt;/head&amp;gt;&lt;br /&gt;
&amp;lt;body&amp;gt;&lt;br /&gt;
    &amp;lt;div id=&amp;quot;foo&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;p&amp;gt;Monkeys&lt;br /&gt;
    &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Sequence of actions:&lt;br /&gt;
# Add a &amp;lt;code&amp;gt;div&amp;lt;/code&amp;gt; element to &amp;lt;code&amp;gt;div#bar&amp;lt;/code&amp;gt;.&lt;br /&gt;
# Move &amp;lt;code&amp;gt;content&amp;lt;/code&amp;gt; element in &amp;lt;code&amp;gt;div#bar&amp;lt;/code&amp;gt; template as the first child of &amp;lt;code&amp;gt;div&amp;lt;/code&amp;gt;&lt;br /&gt;
What happens?&lt;br /&gt;
&lt;br /&gt;
==Dynamicity of Rules==&lt;br /&gt;
As XBL2 spec&#039;d today, the [http://dev.w3.org/2006/xbl2/Overview.html#includes includes] attribute is fully dynamic. That is, changing this attribute results in node redistribution. Being able to control node distribution from outside of the shadow subtree seems like a useful feature. Consider this example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
&amp;lt;head&amp;gt;&lt;br /&gt;
    &amp;lt;binding element=&amp;quot;ul.news&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;template&amp;gt;&lt;br /&gt;
            &amp;lt;h2&amp;gt;Breaking News&amp;lt;/h2&amp;gt;&lt;br /&gt;
            &amp;lt;ul id=&amp;quot;breaking&amp;quot;&amp;gt;&lt;br /&gt;
                &amp;lt;content includes=&amp;quot;li.breaking&amp;quot;&amp;gt;&amp;lt;/content&amp;gt;&lt;br /&gt;
            &amp;lt;/ul&amp;gt;&lt;br /&gt;
            &amp;lt;h2&amp;gt;Other News&amp;lt;/h2&amp;gt;&lt;br /&gt;
            &amp;lt;ul id=&amp;quot;other&amp;quot;&amp;gt;&lt;br /&gt;
                &amp;lt;content&amp;gt;&amp;lt;/content&amp;gt;&lt;br /&gt;
            &amp;lt;/ul&amp;gt;&lt;br /&gt;
        &amp;lt;/template&amp;gt;&lt;br /&gt;
    &amp;lt;/binding&amp;gt;&lt;br /&gt;
&amp;lt;/head&amp;gt;&lt;br /&gt;
&amp;lt;body&amp;gt;&lt;br /&gt;
    &amp;lt;ul class=&amp;quot;news&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;li class=&amp;quot;breaking&amp;quot;&amp;gt;Santa seen crossing Atlantic&amp;lt;/li&amp;gt;&lt;br /&gt;
        &amp;lt;li&amp;gt;Pies pose serious health risk, scientists say&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here, the importance of the news item is controlled outside of the shadow subtree. By setting/removing class &amp;lt;code&amp;gt;breaking&amp;lt;/code&amp;gt; on a news item, the consumer of the binding can move it in and out of the breaking news section. Implementing this without dynamic rules seems cumbersome and non-trivial.&lt;/div&gt;</summary>
		<author><name>Arv</name></author>
	</entry>
</feed>