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

Criando aplicações componentizadas com Polymer

Criando aplicações componentizadas com Polymer

Slides da palestra completa que aconteceu no CEJS 2017 em Fortaleza, no dia 13 de Maio de 2017.

Felipe Sousa

May 16, 2017
Tweet

More Decks by Felipe Sousa

Other Decks in Programming

Transcript

  1. Polymer is a JavaScript library that helps you create custom

    reusable HTML elements, and use them to build performant, maintainable apps.
  2. Our mission is to make life better for users and

    developers, by helping developers unlock the web platform’s full potential and by spurring the web platform to evolve and improve.
  3. Shadow-dom Method of establishing and maintaining functional boundaries between DOM

    subtrees and how these subtrees interact with each other within a document tree.
  4. class FlagIcon extends HTMLElement { constructor() { super(); this._countryCode =

    null; } static get observedAttributes() { return ["country"]; } attributeChangedCallback(name, oldValue, newValue) { this._countryCode = newValue; this._updateRendering(); } get country() { return this._countryCode; } set country(v) { this.setAttribute("country", v); } _updateRendering() { /* update the flag icon */ } }
  5. Templates Method for declaring inert DOM subtrees in HTML and

    manipulating them to instantiate document fragments with identical contents
  6. <link rel=“import” href=“../polymer/polymer.html”> <dom-module id="my-personal-component"> <template> <style> :host { …

    } </style> <h1> Hello! I’m a personal component! </h1> </template> <script> Polymer({ is: “my-personal-component” }); </script> </dom-module>
  7. <link rel=“import” href=“../polymer/polymer.html”> <dom-module id="my-personal-component"> <template> <style> :host { …

    } </style> <h1> Hello! I’m a personal component! </h1> </template> <script> Polymer({ is: “my-personal-component” }); </script> </dom-module> Imports
  8. <link rel=“import” href=“../polymer/polymer.html”> <dom-module id="my-personal-component"> <template> <style> :host { …

    } </style> <h1> Hello! I’m a personal component! </h1> </template> <script> Polymer({ is: “my-personal-component” }); </script> </dom-module> Custom Elements
  9. <link rel=“import” href=“../polymer/polymer.html”> <dom-module id="my-personal-component"> <template> <style> :host { …

    } </style> <h1> Hello! I’m a personal component! </h1> </template> <script> Polymer({ is: “my-personal-component” }); </script> </dom-module> Templates
  10. <link rel=“import” href=“../polymer/polymer.html”> <dom-module id="my-personal-component"> <template> <style> :host { …

    } </style> <h1> Hello! I’m a personal component! </h1> </template> <script> Polymer({ is: “my-personal-component” }); </script> </dom-module> Component!
  11. <link rel=“import” href=“../polymer/polymer.html”> <dom-module id="my-personal-component"> <template> <style> :host { …

    } </style> <h1> Hello! I’m a component! </h1> </template> <script> </script> </dom-module> Component! - Polymer 2.0 class DomElement extends Polymer.Element { static get is() { return “my-personal-component”; } } customElements.define(DomElement.is, DomElement);
  12. • UI • Properties, variables • Binds • Events/Listeners •

    Routes • Requests • Performance • Accessibility • Tests
  13. <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width,

    minimum-scale=1, initial-scale=1, user-scalable=yes"> <title>Document Title</title> <meta name="description" content="space description"> <link rel="manifest" href="/manifest.json"> <script> window.Polymer = { dom: 'shadow' } </script> <script src="/bower_components/webcomponentsjs/webcomponents.js"></script> <link rel="import" href="my-app.html"> </head> <body> <my-app></my-app> </body> </html> polyfill
  14. <link rel="import" href="bower_components/polymer/polymer.html"> <dom-module id="my-component"> <template> <style> :host { /*your

    css here*/ } </style> <!-- Your content here --> </template> <script> Polymer({ is: "my-component" }); </script> </dom-module>
  15. <link rel="import" href="bower_components/polymer/polymer.html"> <dom-module id="my-component"> <template> <style> :host { /*your

    css here*/ } </style> <!-- Your content here --> </template> <script> Polymer({ is: "my-component", properties: { propertie_name: { type: property_type, value: property_value } } }); </script> </dom-module>
  16. <link rel="import" href="bower_components/polymer/polymer.html"> <dom-module id="my-component"> <template> <style> :host { /*your

    css here*/ } </style> <h1>[[property_name]]</h1> </template> <script> Polymer({ is: "my-component", properties: { propertie_name: { type: property_type, value: property_value } } }); </script> </dom-module>
  17. <link rel="import" href="bower_components/polymer/polymer.html"> <dom-module id="my-component"> <template> <style> :host { /*your

    css here*/ } </style> <h1>{{property_name}}</h1> </template> <script> Polymer({ is: "my-component", properties: { propertie_name: { type: property_type, value: property_value } } }); </script> </dom-module>
  18. <link rel="import" href="bower_components/polymer/polymer.html"> <dom-module id="my-component"> <template> <style> :host { /*your

    css here*/ } </style> <h1>{{property_name}}</h1> <input type=“text” value=“{{property_name::input}}”> </template> <script> Polymer({ is: "my-component", properties: { propertie_name: { type: property_type, value: property_value } } }); </script> </dom-module>
  19. <link rel="import" href="bower_components/polymer/polymer.html"> <dom-module id="my-component"> <template> <style> :host { /*your

    css here*/ } </style> <button on-click=“my_method”>Click here</button> </template> <script> Polymer({ is: "my-component", my_method: function () { // do something } }); </script> </dom-module>
  20. <link rel="import" href="/polymer/polymer.html"> <link rel="import" href="./my-second-component.html"> <dom-module id="my-component"> <template> <style>

    :host { display: block; } </style> <my-second-component name="name_property"> </my-second-component> </template> <script> Polymer({ is: "my-component", properties: { name_property: { type: String, value: "CEJS" } } }); </script> </dom-module>
  21. <link rel="import" href="/polymer/polymer.html"> <dom-module id=“my-second-component”> <template> <style> :host { display:

    block; } </style> <p> [[name]] </p> // “CEJS” </template> <script> Polymer({ is: "my-second-component", properties: { name: { type: String, value: "" } } }); </script> </dom-module>
  22. <link rel="import" href="/polymer/polymer.html"> <dom-module id="my-component"> <template> <style> :host { display:

    block; } </style> <button on-click=“my_method”>click here</button> </template> <script> Polymer({ is: "my-component", my_method: function () { this.fire("custom_event", { // your data here }) } }); </script> </dom-module>
  23. <link rel="import" href="/polymer/polymer.html"> <dom-module id="my-component"> <template> <style> :host { display:

    block; } </style> <!-- your content here --> </template> <script> Polymer({ is: "my-component", listeners: { "custom_event": "listen_custom_event" }, listen_custom_event: function (e) { console.log(e.detail); // contain detail os method. } }); </script> </dom-module>
  24. App location Response Padrão da rota Dados da Rota Dados

    da Sub-rota <app-route route="{{route}}" pattern="/:page" data="{{_data}}" tail="{{_tail}}"> </app-route>
  25. <iron-pages selected="{{_data.page}}" attr-for-selected="name" selected- attribute="visible" fallback-selection="404"> <home-app name="home" route="_tail"></home-app> <curiosities-app

    name="curiosities" route="_tail"></curiosities-app> <favorites-app name="favorites" route="_tail"></favorites-app> <about-app name="about" route=“_tail"></about-app> <404—app name="404"></404-app> </iron-pages>