Upgrade to Pro — share decks privately, control downloads, hide ads and more …

In Search of Front-end Modularity

In Search of Front-end Modularity

Given at jQuery Conference - Austin 2013

Front-end developers must create complex solutions with limited available tooling in browser environments in order to modularize their applications and produce reusable code.

With new specs like web components, developers are now able to leverage existing knowledge to build widgets and components that can be reused easily.

In this talk, we explore the current state of modular browser components and discuss newly available libraries and frameworks to provide attendees with the tools to move towards optimized modularization.

Juan Pablo Buriticá

September 11, 2013
Tweet

More Decks by Juan Pablo Buriticá

Other Decks in Programming

Transcript

  1. ★ Functions ★ Libraries ★ Frameworks ★ Architectures Complexity is

    present at all levels Wednesday, September 11, 13
  2. Functional Elements ˒ Reusable ˒ Isolated ˒ Self-contained ˒ Promote

    separation of concerns ˒ Allow composition Wednesday, September 11, 13
  3. Ok so nature does it, how does this help me

    front-end? Wednesday, September 11, 13
  4. ˒ Provide scalability ˒ Structure ˒ Ease of change ˒

    Testability ˒ Lower Cost ˒ Flexibility ˒ Augmentation Wednesday, September 11, 13
  5. Great, but this is not news. We’ve been trying to

    do it for a long time. Wednesday, September 11, 13
  6. ˒HTML ˒CSS ˒JS * Not necessarily a 1 to 1

    relationship Wednesday, September 11, 13
  7. Files are getting too big Break stuff into more files

    with less complexity Wednesday, September 11, 13
  8. Modular Front-end Architectures ★ Everything is a component ★ Small

    Core ★ Base (DOM, utils, etc) ★ Messaging via events AuraJS and Twitter Flight Wednesday, September 11, 13
  9. Web Components ★ Templates ★ Decorators ★ Custom Elements ★

    Shadow DOM ★ HTML Imports ★ Other stuff (mutation observers, pointer events, data binding) Wednesday, September 11, 13
  10. Templates <template id="commentTemplate"> <div> <img src=""> <div class="comment-text"></div> </div> </template>

    <script> function addComment(imageUrl, text) { var t = document.querySelector("#commentTemplate"); var comment = t.content.cloneNode(true); // Populate content. comment.querySelector('img').src = imageUrl; comment.querySelector('.comment-text').textContent = text; document.body.appendChild(comment); } </script> Wednesday, September 11, 13
  11. Decorators ★ Do not have a spec yet! ★ Are

    meant to enhance or override presentation of an existing element ★ In theory, would be applied by CSS Wednesday, September 11, 13
  12. Custom Elements ★ Allow author definition of DOM elements ★

    Access to prototype via nested <script> ★ Element lifecycle callbacks ★ Available via markup and scripts ★ Are extensible via extends=”” attribute Wednesday, September 11, 13
  13. <element extends="my-element" name="tick-tock-clock"> <template> <span id="hh"></span> <span id="sep">:</span> <span id="mm"></span>

    </template> <script> var template = document.currentScript.parentNode.querySelector('template'); function start() { this.tick(); this._interval = window.setInterval(this.tick.bind(this), 1000); } function stop() { window.clearInterval(this._interval); } function fmt(n) { return (n < 10 ? '0' : '') + n; } ({ readyCallback: function () { // awesome codez }, insertedCallback: start, removedCallback: stop, tick: function () { // awesome codez }, chime: function () { // awesome codez } }); </script> </element> Wednesday, September 11, 13
  14. Shadow DOM ★ Provides encapsulation and enables composition ★ The

    meat of web components ★ Complex concepts which go beyond scope of this talk ★ Check out the spec https://dvcs.w3.org/hg/webcomponents/raw-file/tip/spec/shadow/index.html Wednesday, September 11, 13
  15. HTML Imports ★ Allow components to be loaded from external

    resources <link rel="import" href="clock.html"> Wednesday, September 11, 13
  16. Polyfills available*!! ★ Polymer.js (Google) http://www.polymer-project.org ★ Brick + X-Tag

    (Mozilla) http://mozilla.github.io/brick/ ★ *subject to browser compatibility Wednesday, September 11, 13
  17. The search of ideal modularity will end when our applications

    stop increasing in complexity Wednesday, September 11, 13
  18. Web Component Resources ★ http://www.w3.org/TR/2013/WD-components- intro-20130606/ ★ http://customelements.io/ ★ http://www.polymer-project.org/

    ★ http://mozilla.github.io/brick/ ★ https://plus.google.com/103330502635338602217/posts ★ https://www.youtube.com/watch?v=2txPYQOWBtg Wednesday, September 11, 13
  19. Shadow DOM Resources ★ https://dvcs.w3.org/hg/webcomponents/raw- file/tip/spec/shadow/index.html ★ http://www.html5rocks.com/en/tutorials/ webcomponents/shadowdom/ ★

    http://www.sitepoint.com/dark-shadow-dom/ ★ http://glazkov.com/2011/01/14/what-the-heck- is-shadow-dom/ Wednesday, September 11, 13
  20. Photo Credits ★ http://www.flickr.com/photos/postbear/8560714141/ ★ http://www.flickr.com/photos/wellcomeimages/6795233302/ ★ http://commons.wikimedia.org/wiki/File:Neurons-axons- dendrites-synapses.PNG ★

    http://www.aquascapingworld.com/gallery/images/ 1/1_plantedtank_islandscape2.jpg ★ http://www.flickr.com/photos/25408600@N00/61523666/ ★ http://www.flickr.com/photos/webstock06/5453863583/ Wednesday, September 11, 13