A place to cache linked articles (think custom and personal wayback machine)
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

index.md 7.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. title: Extensibility
  2. url: https://adactio.com/journal/8276
  3. hash_url: 6cef4c24facfb5fd7a7f9049232b1a56
  4. <p><a href="https://adactio.com/journal/7431">I’ve said it before</a>, but I’m going to reiterate my conflicted feelings about <a href="http://webcomponents.org/">Web Components</a>:</p>
  5. <blockquote>
  6. <p>I have conflicting feelings about Web Components. I am simultaneously very excited and very nervous.</p>
  7. </blockquote>
  8. <p>There are broadly two ways that they could potentially be used:</p>
  9. <ol>
  10. <li>Web Components are used by developers to incrementally add more powerful elements to their websites. This evolutionary approach feels very much in line with the thinking behind <a href="https://extensiblewebmanifesto.org/">the extensible web manifesto</a>. Or:</li>
  11. <li>Web Components are used by developers as a monolithic platform, much like Angular or Ember is used today. The end user either gets everything or they get nothing.</li>
  12. </ol>
  13. <p>The second scenario is a much more revolutionary approach—sweep aside the web that has come before, and usher in a new golden age of Web Components. Personally, I’m not comfortable with that kind of year-zero thinking. I prefer <a href="http://www.w3.org/TR/html-design-principles/#evolution-not-revolution">evolution over revolution</a>:</p>
  14. <blockquote>
  15. <p>Revolutions sometimes change the world to the better. Most often, however, it is better to evolve an existing design rather than throwing it away. This way, authors don’t have to learn new models and content will live longer. Specifically, this means that one should prefer to design features so that old content can take advantage of new features without having to make unrelated changes. And implementations should be able to add new features to existing code, rather than having to develop whole separate modes.</p>
  16. </blockquote>
  17. <p>The evolutionary model is exemplified by the design of HTML 5.</p>
  18. <p>The revolutionary model is exemplified by the design of XHTML 2.</p>
  19. <p>I really hope that the Web Components model goes down the first route.</p>
  20. <p>Up until recently, my inner Web Components pendulum was swinging towards the hopeful end of my spectrum of anticipation. That was mainly driven by the ability of <a href="http://www.w3.org/TR/custom-elements/">custom elements</a> to <a href="http://www.w3.org/TR/custom-elements/#type-extension-semantics">extend existing HTML elements</a>.</p>
  21. <p>So, for example, instead of creating a new element like this:</p>
  22. <pre><code>&lt;taco-button&gt;...&lt;/taco-button&gt;
  23. </code></pre>
  24. <p>…you can piggyback off the existing semantics of the <code>button</code> element like this:</p>
  25. <pre><code>&lt;button is="taco-button"&gt;...&lt;/button&gt;
  26. </code></pre>
  27. <p>For a real-world example, see <a href="https://github.com/github/time-elements">Github’s use of <code>&lt;time is="time-ago"&gt;</code></a>.</p>
  28. <p>I wrote about creating <a href="https://adactio.com/journal/7967">responsible Web Components</a>:</p>
  29. <blockquote>
  30. <p>That means we can use web components as a form of progressive enhancement, turbo-charging pre-existing elements instead of creating brand new elements from scratch. That way, we can easily provide fallback content for non-supporting browsers.</p>
  31. <p>I’d like to propose that a fundamental principle of good web component design should be: “Where possible, extend an existing HTML element instead of creating a new element from scratch.”</p>
  32. </blockquote>
  33. <p>Peter Gasston also has a great post on <a href="http://www.broken-links.com/2015/01/27/best-practice-creating-custom-elements/">best practice for creating custom elements</a>:</p>
  34. <blockquote>
  35. <p>It’s my opinion that, for as long as there is a dependence on JS for custom elements, we should extend existing elements when writing custom elements. It makes sense for developers, because new elements have access to properties and methods that have been defined and tested for many years; and it makes sense for users, as they have fallback in case of JS failure, and baked-in accessibility fundamentals.</p>
  36. </blockquote>
  37. <p>But now it looks like this superpower of custom elements is being <a href="https://lists.w3.org/Archives/Public/public-webapps/2015JanMar/0206.html">nipped in the bud</a>:</p>
  38. <blockquote>
  39. <p>It also does not address subclassing normal elements. Again, while
  40. that seems desirable the current ideas are not attractive long term
  41. solutions. Punting on it in order to ship a v1 available everywhere
  42. seems preferable.</p>
  43. </blockquote>
  44. <p>Now, I’m not particularly wedded to the syntax of using the <code>is=""</code> attribute to extend existing elements …but I do think that the ability to extend existing elements declaratively is vital. I’m not alone, although I may very well be in the minority.</p>
  45. <p>Bruce has <a href="https://lists.w3.org/Archives/Public/public-webapps/2015JanMar/0368.html">outlined some use cases</a> and Steve Faulkner <a href="https://lists.w3.org/Archives/Public/public-webapps/2015JanMar/0360.html">has enumerated the benefits of declarative extensibility</a>:</p>
  46. <blockquote>
  47. <p>I think being able to extend existing elements has potential value to
  48. developers far beyond accessibility (it just so happens that accessibility
  49. is helped a lot by re-use of existing HTML features.)</p>
  50. </blockquote>
  51. <p>Bruce concurs:</p>
  52. <blockquote>
  53. <p>Like Steve, I’ve no particularly affection (or enmity) towards the
  54. <code>&lt;input type="radio" is="luscious-radio"&gt;</code> syntax. But I’d like to know, if it’s dropped, how progressive enhancement can be achieved so we
  55. don’t lock out users of browsers that don’t have web components
  56. capabilities, JavaScript disabled or proxy browsers. If there is a
  57. concrete plan, please point me to it. If there isn’t, it’s
  58. irresponsible to drop a method that we can see working in the example
  59. above with nothing else to replace it.</p>
  60. </blockquote>
  61. <p>He adds:</p>
  62. <blockquote>
  63. <p>I also have a niggling worry that this may affect the uptake of web
  64. components.</p>
  65. </blockquote>
  66. <p>I think he’s absolutely right. I think there are many developers out there in a similar position to me, uncertain exactly what to make of this new technology. I was looking forward to getting really stuck into Web Components and figuring out ways of creating powerful little extensions that I could start using now. But if Web Components turn out to be an all-or-nothing technology—a “platform”, if you will—then I will not only <em>not</em> be using them, I’ll be actively arguing against their use.</p>
  67. <p>I really hope that doesn’t happen, but I must admit I’m not hopeful—my inner pendulum has swung firmly back towards the nervous end of my anticipation spectrum. That’s because I’m getting the distinct impression that the priorities being considered for Web Components are those of JavaScript framework creators, rather than web developers looking to add incremental improvements while maintaining backward compatibility.</p>
  68. <p>If that’s the case, then Web Components will be made in the image of existing monolithic MVC frameworks that require JavaScript to do anything, even rendering content. To me, that’s a dystopian vision, one I can’t get behind.</p>