Slide 1

Slide 1 text

+Monica Dinculescu @notwaldorf BILLIONS SERVED LESSONS LEARNED (A POLYMER STORY)

Slide 2

Slide 2 text

@notwaldorf

Slide 3

Slide 3 text

THE WEB IS LIKE A SHARK. IT HAS TO CONSTANTLY MOVE FORWARD OR IT DIES WOODY ALLEN

Slide 4

Slide 4 text

THE WEB IS LIKE A SHARK. IT HAS TO CONSTANTLY MOVE FORWARD OR IT DIES POLYMER WOODY ALLEN

Slide 5

Slide 5 text

POLYMER 1.0 one size fits all

Slide 6

Slide 6 text

... Polymer({ is: 'paper-input', behaviors: [...], properties: {...}, listeners: {...}, hostAttributes: {...}, });

Slide 7

Slide 7 text

WEB STANDARDS (v0) kind of a mess, tbh

Slide 8

Slide 8 text

BASIC USE CASE well lit path!

Slide 9

Slide 9 text

ADVANCED USE CASE ???

Slide 10

Slide 10 text

DIFFERENT NEEDS leaf vs view nodes

Slide 11

Slide 11 text

POLYMER 1.0 one size fits all

Slide 12

Slide 12 text

POLYMER 1.0 POLYMER 2.0 one size fits all a la carte

Slide 13

Slide 13 text

WEB STANDARDS (v1) are a go!

Slide 14

Slide 14 text

YOU USE
 THE PLATFORM WE EMPOWER YOU

Slide 15

Slide 15 text

POLYMER 1.0 “do less to be fast”

Slide 16

Slide 16 text

POLYMER 1.0 POLYMER 2.0 “do less to be fast” “do more if you need to”

Slide 17

Slide 17 text

WE HAVE OPTIONS!

Slide 18

Slide 18 text

HTMLElement

Slide 19

Slide 19 text

HTMLElement getters/setters

Slide 20

Slide 20 text

HTMLElement getters/setters templates

Slide 21

Slide 21 text

HTMLElement getters/setters templates {{ }}

Slide 22

Slide 22 text

HTMLElement getters/setters templates {{ }}

Slide 23

Slide 23 text

HTMLElement PropertyAccessors TemplateStamp PropertyEffects Polymer.Element

Slide 24

Slide 24 text

HTMLElement PropertyAccessors TemplateStamp PropertyEffects Polymer.Element 2.2 KB 3.4 KB 8.8 KB 11 KB

Slide 25

Slide 25 text

myElement.counter = 3;

Slide 26

Slide 26 text

aspiring-chauffeur.glitch.me

Slide 27

Slide 27 text

HTMLElement Polymer.PropertyAccessors Polymer.TemplateStamp Polymer.PropertyEffects Polymer.Element 1 2 3 4 5

Slide 28

Slide 28 text

class MyElement extends HTMLElement { ... } customElements.define('my-element', MyElement);

Slide 29

Slide 29 text

Lifecycle methods! class MyElement extends HTMLElement { constructor() { ... } connectedCallback() { ... } disconnectedCallback() { ... } attributeChangedCallback(attr, oldValue, newValue) { ... } static get observedAttributes() { return [...]; } }

Slide 30

Slide 30 text

Lifecycle methods! class MyElement extends HTMLElement { constructor() { ... } connectedCallback() { ... } disconnectedCallback() { ... } attributeChangedCallback(attr, oldValue, newValue) { ... } static get observedAttributes() { return [...]; } }

Slide 31

Slide 31 text

Lifecycle methods! class MyElement extends HTMLElement { constructor() { ... } connectedCallback() { ... } disconnectedCallback() { ... } attributeChangedCallback(attr, oldValue, newValue) { ... } static get observedAttributes() { return [...]; } }

Slide 32

Slide 32 text

Lifecycle methods! class MyElement extends HTMLElement { constructor() { ... } connectedCallback() { ... } disconnectedCallback() { ... } attributeChangedCallback(attr, oldValue, newValue) { ... } static get observedAttributes() { return [...]; } }

Slide 33

Slide 33 text

class MyElement extends HTMLElement { constructor() { super(); this._counter = 0; this.attachShadow({mode: 'open'}); } connectedCallback() { this.render(); } static get observedAttributes() { return ['counter', 'limit']; } attributeChangedCallback(attr, oldValue, newValue) { if (oldValue !== newValue) { this[attr] = newValue; } } get counter() { return this._counter; } set counter(value) { if (value != this._counter) { this._counter = parseInt(value); this.setAttribute('counter', value); this.display(); } }

Slide 34

Slide 34 text

class MyElement extends HTMLElement { constructor() { super(); this._counter = 0; this.attachShadow({mode: 'open'}); } connectedCallback() { this.render(); } static get observedAttributes() { return ['counter', 'limit']; } attributeChangedCallback(attr, oldValue, newValue) { if (oldValue !== newValue) { this[attr] = newValue; } } get counter() { return this._counter; } set counter(value) { if (value != this._counter) { this._counter = parseInt(value); this.setAttribute('counter', value); this.display(); } } Make the shadow root

Slide 35

Slide 35 text

class MyElement extends HTMLElement { constructor() { super(); this._counter = 0; this.attachShadow({mode: 'open'}); } connectedCallback() { this.render(); } static get observedAttributes() { return ['counter', 'limit']; } attributeChangedCallback(attr, oldValue, newValue) { if (oldValue !== newValue) { this[attr] = newValue; } } get counter() { return this._counter; } set counter(value) { if (value != this._counter) { this._counter = parseInt(value); this.setAttribute('counter', value); this.display(); } } Add things to it

Slide 36

Slide 36 text

render() { var button = document.createElement('button'); button.innerHTML = ''; button.addEventListener('click', this.increment.bind(this)); this.shadowRoot.appendChild(button); this.output = document.createElement('span'); this.shadowRoot.appendChild(this.output); // Some styles for pretty. this.style.display = 'block'; this.style.fontSize = '30px'; this.output.style.marginLeft = '10px'; button.style.background = 'transparent'; button.style.fontSize = 'inherit'; button.style.border = 'none'; button.style.cursor = 'pointer'; }

Slide 37

Slide 37 text

render() { var button = document.createElement('button'); button.innerHTML = ''; button.addEventListener('click', this.increment.bind(this)); this.shadowRoot.appendChild(button); this.output = document.createElement('span'); this.shadowRoot.appendChild(this.output); // Some styles for pretty. this.style.display = 'block'; this.style.fontSize = '30px'; this.output.style.marginLeft = '10px'; button.style.background = 'transparent'; button.style.fontSize = 'inherit'; button.style.border = 'none'; button.style.cursor = 'pointer'; }

Slide 38

Slide 38 text

render() { var button = document.createElement('button'); button.innerHTML = ''; button.addEventListener('click', this.increment.bind(this)); this.shadowRoot.appendChild(button); this.output = document.createElement('span'); this.shadowRoot.appendChild(this.output); // Some styles for pretty. this.style.display = 'block'; this.style.fontSize = '30px'; this.output.style.marginLeft = '10px'; button.style.background = 'transparent'; button.style.fontSize = 'inherit'; button.style.border = 'none'; button.style.cursor = 'pointer'; }

Slide 39

Slide 39 text

class MyElement extends HTMLElement { constructor() { super(); this._counter = 0; this.attachShadow({mode: 'open'}); } connectedCallback() { this.render(); } static get observedAttributes() { return ['counter', 'limit']; } attributeChangedCallback(attr, oldValue, newValue) { if (oldValue !== newValue) { this[attr] = newValue; } } get counter() { return this._counter; } set counter(value) { if (value != this._counter) { this._counter = parseInt(value); this.setAttribute('counter', value); this.display(); } } Update properties

Slide 40

Slide 40 text

class MyElement extends HTMLElement { constructor() { super(); this._counter = 0; this.attachShadow({mode: 'open'}); } connectedCallback() { this.render(); } static get observedAttributes() { return ['counter', 'limit']; } attributeChangedCallback(attr, oldValue, newValue) { if (oldValue !== newValue) { this[attr] = newValue; } } get counter() { return this._counter; } set counter(value) { if (value != this._counter) { this._counter = parseInt(value); this.setAttribute('counter', value); this.display(); } } Optional: reflect attribute

Slide 41

Slide 41 text

class MyElement extends HTMLElement { constructor() { super(); this._counter = 0; this.attachShadow({mode: 'open'}); } connectedCallback() { this.render(); } static get observedAttributes() { return ['counter', 'limit']; } attributeChangedCallback(attr, oldValue, newValue) { if (oldValue !== newValue) { this[attr] = newValue; } } get counter() { return this._counter; } set counter(value) { if (value != this._counter) { this._counter = parseInt(value); this.setAttribute('counter', value); this.display(); } } Actual useful code

Slide 42

Slide 42 text

class MyElement extends HTMLElement { constructor() { super(); this._counter = 0; this.attachShadow({mode: 'open'}); } connectedCallback() { this.render(); } static get observedAttributes() { return ['counter', 'limit']; } attributeChangedCallback(attr, oldValue, newValue) { if (oldValue !== newValue) { this[attr] = newValue; } } get counter() { return this._counter; } set counter(value) { if (value != this._counter) { this._counter = parseInt(value); this.setAttribute('counter', value); this.display(); } } display() { this.output.innerHTML = ''.repeat(this.counter); } Actual useful code

Slide 43

Slide 43 text

ONCE MORE, WITH FEELING LESS BOILERPLATE

Slide 44

Slide 44 text

HTMLElement Polymer.PropertyAccessors Polymer.TemplateStamp Polymer.PropertyEffects Polymer.Element 1 2 3 4 5

Slide 45

Slide 45 text

class MyElement extends HTMLElement { constructor() { ... } connectedCallback() { this.render(); } static get observedAttributes() { return ['counter', 'limit']; } attributeChangedCallback(attr, oldValue, newValue) { if (oldValue !== newValue) { this[attr] = newValue; } } get counter() { return this._counter; } set counter(value) { if (value != this._counter) { this._counter = parseInt(value); this.setAttribute('counter', value); this.display(); } }

Slide 46

Slide 46 text

class MyElement extends Polymer.PropertyAccessors(HTMLElement) { constructor() { ... } connectedCallback() { this.render(); } static get observedAttributes() { return ['counter', 'limit']; } attributeChangedCallback(attr, oldValue, newValue) { if (oldValue !== newValue) { this[attr] = newValue; } } get counter() { return this._counter; } set counter(value) { if (value != this._counter) { this._counter = parseInt(value); this.setAttribute('counter', value); this.display(); } }

Slide 47

Slide 47 text

class MyElement extends Polymer.PropertyAccessors(HTMLElement) { constructor() { ... } connectedCallback() { this.render(); this._enableProperties(); } static get observedAttributes() { return ['counter', 'limit']; } attributeChangedCallback(attr, oldValue, newValue) { if (oldValue !== newValue) { this[attr] = newValue; } } get counter() { return this._counter; } set counter(value) { if (value != this._counter) { this._counter = parseInt(value); this.setAttribute('counter', value); this.display(); } } Turn on accessors

Slide 48

Slide 48 text

class MyElement extends Polymer.PropertyAccessors(HTMLElement) { constructor() { ... } connectedCallback() { this._enableProperties(); } ready() { this.render(); super.ready(); } static get observedAttributes() { return ['counter', 'limit']; } attributeChangedCallback(attr, oldValue, newValue) { if (oldValue !== newValue) { this[attr] = newValue; } } get counter() { return this._counter; } set counter(value) { if (value != this._counter) { this._counter = parseInt(value); this.setAttribute('counter', value); this.display(); } Ready!

Slide 49

Slide 49 text

class MyElement extends Polymer.PropertyAccessors(HTMLElement) { constructor() { ... } connectedCallback() { this._enableProperties(); } ready() { this.render(); super.ready(); } static get observedAttributes() { return ['counter', 'limit']; } attributeChangedCallback(attr, oldValue, newValue) { if (oldValue !== newValue) { this[attr] = newValue; } } get counter() { return this._counter; } set counter(value) { if (value != this._counter) { this._counter = parseInt(value); this.setAttribute('counter', value); this.display(); }

Slide 50

Slide 50 text

class MyElement extends Polymer.PropertyAccessors(HTMLElement) { constructor() { ... } connectedCallback() { this._enableProperties(); } ready() { this.render(); super.ready(); } static get observedAttributes() { return ['counter', 'limit']; } attributeChangedCallback(attr, oldValue, newValue) { if (oldValue !== newValue) { this[attr] = newValue; } } get counter() { return this._counter; } set counter(value) { if (value != this._counter) { this._counter = parseInt(value); this.setAttribute('counter', value); this.display(); }

Slide 51

Slide 51 text

class MyElement extends Polymer.PropertyAccessors(HTMLElement) { constructor() { ... } connectedCallback() { this._enableProperties(); } ready() { this.render(); super.ready(); } static get observedAttributes() { return ['counter', 'limit']; } _propertiesChanged(currentProps, changedProps, oldProps) { if ('counter' in changedProps) { // Only reflect this this.setAttribute('counter', changedProps.counter); this.display(); } } } Actual useful code!

Slide 52

Slide 52 text

class MyElement extends Polymer.PropertyAccessors(HTMLElement) { constructor() { ... } connectedCallback() { this._enableProperties(); } ready() { this.render(); super.ready(); } static get observedAttributes() { return ['counter', 'limit']; } _propertiesChanged(currentProps, changedProps, oldProps) { if ('counter' in changedProps) // Only reflect this this.setAttribute(‘counter’, changedProps.counter); this.display(); } } } MyHTMLElement.createPropertiesForAttributes(); Do the boilerplate!

Slide 53

Slide 53 text

HTMLElement Polymer.PropertyAccessors Polymer.TemplateStamp Polymer.PropertyEffects Polymer.Element 1 2 3 4 5

Slide 54

Slide 54 text

CSS/HTML in JS render() { var button = document.createElement('button'); button.innerHTML = ''; button.addEventListener('click', this.increment); this.shadowRoot.appendChild(button); this.output = document.createElement('span'); this.shadowRoot.appendChild(this.output); this.style.display = 'block'; this.style.fontSize = '30px'; this.output.style.marginLeft = '10px'; button.style.background = 'transparent'; button.style.fontSize = 'inherit'; button.style.border = 'none'; button.style.cursor = 'pointer'; }

Slide 55

Slide 55 text

render() { var button = document.createElement('button'); button.innerHTML = ''; button.addEventListener('click', this.increment); this.shadowRoot.appendChild(button); this.output = document.createElement('span'); this.shadowRoot.appendChild(this.output); this.style.display = 'block'; this.style.fontSize = '30px'; this.output.style.marginLeft = '10px'; button.style.background = 'transparent'; button.style.fontSize = 'inherit'; button.style.border = 'none'; button.style.cursor = 'pointer'; } CSS/HTML in JS

Slide 56

Slide 56 text

CSS/HTML in CSS/HTML render() { var button = document.createElement('button'); button.innerHTML = ''; button.addEventListener('click', this.increment); this.shadowRoot.appendChild(button); this.output = document.createElement('span'); this.shadowRoot.appendChild(this.output); this.style.display = 'block'; this.style.fontSize = '30px'; this.output.style.marginLeft = '10px'; button.style.background = 'transparent'; button.style.fontSize = 'inherit'; button.style.border = 'none'; button.style.cursor = 'pointer'; } :host { display: block; font-size: 30px; } span { margin-left: 10px; } button { background: transparent; font-size: inherit; border: none; cursor: pointer; }

Slide 57

Slide 57 text

CSS/HTML in CSS/HTML :host { display: block; font-size: 30px; } span { margin-left: 10px; } button { background: transparent; font-size: inherit; border: none; cursor: pointer; } render() { var button = document.createElement('button'); button.innerHTML = ''; button.addEventListener('click', this.increment); this.shadowRoot.appendChild(button); this.output = document.createElement('span'); this.shadowRoot.appendChild(this.output); this.style.display = 'block'; this.style.fontSize = '30px'; this.output.style.marginLeft = '10px'; button.style.background = 'transparent'; button.style.fontSize = 'inherit'; button.style.border = 'none'; button.style.cursor = 'pointer'; }

Slide 58

Slide 58 text

render() { var button = document.createElement('button'); button.innerHTML = ''; button.addEventListener('click', this.increment); this.shadowRoot.appendChild(button); this.output = document.createElement('span'); this.shadowRoot.appendChild(this.output); this.style.display = 'block'; this.style.fontSize = '30px'; this.output.style.marginLeft = '10px'; button.style.background = 'transparent'; button.style.fontSize = 'inherit'; button.style.border = 'none'; button.style.cursor = 'pointer'; } :host { display: block; font-size: 30px; } span { margin-left: 10px; } button { background: transparent; font-size: inherit; border: none; cursor: pointer; } CSS/HTML in CSS/HTML

Slide 59

Slide 59 text

:host { display: block; font-size: 30px; } span { margin-left: 10px; } button { background: transparent; font-size: inherit; border: none; cursor: pointer; } Declarative CSS/HTML in CSS/HTML

Slide 60

Slide 60 text

:host { display: block; font-size: 30px; } span { margin-left: 10px; } button { background: transparent; font-size: inherit; border: none; cursor: pointer; } this.$.output CSS/HTML in CSS/HTML

Slide 61

Slide 61 text

WHICH MEANS EVEN LESS BOILERPLATE!

Slide 62

Slide 62 text

class MyHTMLElement extends Polymer.PropertyAccessors(HTMLElement) { constructor() { super(); this._counter = 0; this.attachShadow({mode: 'open'}); } connectedCallback() { this._enableProperties(); } ready() { this.render(); super.ready(); } static get observedAttributes() { return ['counter', 'limit']; } _propertiesChanged(currentProps, changedProps, oldProps) { ... } display() { ... } increment() { ... } render() { ... } } MyHTMLElement.createPropertiesForAttributes();

Slide 63

Slide 63 text

class MyHTMLElement extends Polymer.TemplateStamp(Polymer.PropertyAccessors(HTMLElement)) { constructor() { super(); this._counter = 0; this.attachShadow({mode: 'open'}); } connectedCallback() { this._enableProperties(); } ready() { this.render(); super.ready(); } static get observedAttributes() { return ['counter', 'limit']; } _propertiesChanged(currentProps, changedProps, oldProps) { ... } display() { ... } increment() { ... } render() { ... } } MyHTMLElement.createPropertiesForAttributes();

Slide 64

Slide 64 text

class MyHTMLElement extends Polymer.TemplateStamp(Polymer.PropertyAccessors(HTMLElement)) { constructor() { super(); this._counter = 0; this.attachShadow({mode: 'open'}); } connectedCallback() { this._enableProperties(); } ready() { this.render(); super.ready(); } static get observedAttributes() { return ['counter', 'limit']; } _propertiesChanged(currentProps, changedProps, oldProps) { ... } display() { ... } increment() { ... } render() { ... } } MyHTMLElement.createPropertiesForAttributes(); No more manual render!

Slide 65

Slide 65 text

class MyHTMLElement extends Polymer.TemplateStamp(Polymer.PropertyAccessors(HTMLElement)) { constructor() { super(); this._counter = 0; } connectedCallback() { this._enableProperties(); } ready() { super.ready(); } static get observedAttributes() { return ['counter', 'limit']; } _propertiesChanged(currentProps, changedProps, oldProps) { ... } display() { ... } increment() { ... } } MyHTMLElement.createPropertiesForAttributes();

Slide 66

Slide 66 text

class MyHTMLElement extends Polymer.TemplateStamp(Polymer.PropertyAccessors(HTMLElement)) { constructor() { super(); this._counter = 0; } connectedCallback() { this._enableProperties(); } ready() { this.dom = this._stampTemplate(someTemplate); this.attachShadow({mode: 'open'}).appendChild(this.dom); super.ready(); } static get observedAttributes() { return ['counter', 'limit']; } _propertiesChanged(currentProps, changedProps, oldProps) { ... } display() { ... } increment() { ... } } MyHTMLElement.createPropertiesForAttributes(); Stamp the template

Slide 67

Slide 67 text

HTMLElement Polymer.PropertyAccessors Polymer.TemplateStamp Polymer.PropertyEffects Polymer.Element 1 2 3 4 5

Slide 68

Slide 68 text

class MyHTMLElement extends Polymer.TemplateStamp(Polymer.PropertyAccessors(HTMLElement)) { constructor() { ... } connectedCallback() { ... } ready() { ... } static get observedAttributes() { return ['counter', 'limit']; } _propertiesChanged(currentProps, changedProps, oldProps) { if ('counter' in changedProps) this.setAttribute(‘counter’, changedProps.counter); this.display(); } } display() { ... } increment() { ... } } MyHTMLElement.createPropertiesForAttributes();

Slide 69

Slide 69 text

class MyHTMLElement extends Polymer.PropertyEffects(HTMLElement)) { constructor() { ... } connectedCallback() { ... } ready() { ... } static get observedAttributes() { return ['counter', 'limit']; } _propertiesChanged(currentProps, changedProps, oldProps) { if ('counter' in changedProps) this.setAttribute(‘counter’, changedProps.counter); this.display(); } } display() { ... } increment() { ... } } MyHTMLElement.createPropertiesForAttributes();

Slide 70

Slide 70 text

class MyHTMLElement extends Polymer.PropertyEffects(HTMLElement)) { constructor() { ... } connectedCallback() { ... } ready() { ... } static get observedAttributes() { return ['counter', 'limit']; } _propertiesChanged(currentProps, changedProps, oldProps) { if ('counter' in changedProps) this.setAttribute(‘counter’, changedProps.counter); this.display(); } } display() { ... } increment() { ... } } MyHTMLElement.createPropertiesForAttributes();

Slide 71

Slide 71 text

class MyHTMLElement extends Polymer.PropertyEffects(HTMLElement)) { constructor() { ... } connectedCallback() { ... } ready() { ... } static get observedAttributes() { return ['counter', 'limit']; } display() { ... } increment() { ... } } MyHTMLElement.createPropertiesForAttributes();

Slide 72

Slide 72 text

class MyHTMLElement extends Polymer.PropertyEffects(HTMLElement)) { constructor() { ... } connectedCallback() { ... } ready() { ... } static get observedAttributes() { return ['counter', 'limit']; } display() { ... } increment() { ... } } MyHTMLElement.createPropertiesForAttributes(); MyHTMLElement.createReflectedProperty('counter'); Do the boilerplate!

Slide 73

Slide 73 text

Data binding! /* ... */ display() { this.$.output.innerHTML = ''.repeat(this.counter); }

Slide 74

Slide 74 text

Data binding! /* ... */ [[display(counter)]] display(c) { return ''.repeat(c); }

Slide 75

Slide 75 text

HTMLElement Polymer.PropertyAccessors Polymer.TemplateStamp Polymer.PropertyEffects Polymer.Element 1 2 3 4 5

Slide 76

Slide 76 text

No content

Slide 77

Slide 77 text

class MyHTMLElement extends Polymer.PropertyEffects(HTMLElement)) { constructor() { ... } connectedCallback() { ... } ready() { ... } static get observedAttributes() { return ['counter', 'limit']; } display() { ... } increment() { ... } } MyHTMLElement.createPropertiesForAttributes(); MyHTMLElement.createReflectedProperty('counter');

Slide 78

Slide 78 text

class MyHTMLElement extends Polymer.Element { constructor() { ... } connectedCallback() { ... } ready() { ... } static get observedAttributes() { return ['counter', 'limit']; } display() { ... } increment() { ... } } MyHTMLElement.createPropertiesForAttributes(); MyHTMLElement.createReflectedProperty('counter');

Slide 79

Slide 79 text

class MyHTMLElement extends Polymer.Element { constructor() { ... } connectedCallback() { ... } ready() { ... } static get observedAttributes() { return ['counter', 'limit']; } display() { ... } increment() { ... } } MyHTMLElement.createPropertiesForAttributes(); MyHTMLElement.createReflectedProperty('counter');

Slide 80

Slide 80 text

class MyHTMLElement extends Polymer.Element { static get properties() { return { counter: {type: Number, reflectToAttribute: true, value: 0}, limit: {type: Number} } } display() { ... } increment() { ... } }

Slide 81

Slide 81 text

class MyHTMLElement extends Polymer.Element { static get is() { return 'my-element'; } static get properties() { return { counter: {type: Number, reflectToAttribute: true, value: 0}, limit: {type: Number} } } display() { ... } increment() { ... } } Automatic template finding

Slide 82

Slide 82 text

Automatic template finding ... class MyHTMLElement extends Polymer.Element { ... } customElements.define(MyHTMLElement.is, MyHTMLElement);

Slide 83

Slide 83 text

Automatic template finding ... class MyHTMLElement extends Polymer.Element { ... } customElements.define(MyHTMLElement.is, MyHTMLElement);

Slide 84

Slide 84 text

No content

Slide 85

Slide 85 text

HTMLElement Polymer.PropertyAccessors Polymer.TemplateStamp Polymer.PropertyEffects Polymer.Element 1 2 3 4 5

Slide 86

Slide 86 text

HTMLElement Getters and setters Polymer.TemplateStamp Polymer.PropertyEffects Polymer.Element 1 2 3 4 5

Slide 87

Slide 87 text

HTMLElement Getters and setters CSS in JS -> templates Polymer.PropertyEffects Polymer.Element 1 2 3 4 5

Slide 88

Slide 88 text

HTMLElement Getters and setters CSS in JS -> templates Data binding Polymer.Element 1 2 3 4 5

Slide 89

Slide 89 text

HTMLElement Getters and setters CSS in JS -> templates Data binding Everything + all the convenience 1 2 3 4 5

Slide 90

Slide 90 text

POLYMER 2.0 kinda like jQuery for Web Components

Slide 91

Slide 91 text

POLYMER 2.0 kinda like jQuery for Web Components. In the sense that it helps you out not that it’s old and boring.

Slide 92

Slide 92 text

LIKE…

Slide 93

Slide 93 text

ES6 CLASSES: LESS LIBRARY MORE PLATFORM

Slide 94

Slide 94 text

class MyHTMLElement extends Polymer.Element { static get is() { return 'my-element'; } static get properties() { return { counter: {type: Number, reflectToAttribute: true, value: 0}, limit: {type: Number} } } display() { ... } increment() { ... } }

Slide 95

Slide 95 text

class MyHTMLElement extends Polymer.Element { static get is() { return 'my-element'; } static get properties() { return { counter: {type: Number, reflectToAttribute: true, value: 0}, limit: {type: Number} } } display() { ... } increment() { ... } } Inheritance

Slide 96

Slide 96 text

AND SPEAKING OF INHERITANCE…

Slide 97

Slide 97 text

Base class ... class MyHTMLElement extends Polymer.Element { static get is() { return 'my-element'; } display() {...} ... } customElements.define(MyHTMLElement.is, MyHTMLElement);

Slide 98

Slide 98 text

class MyOtherElement extends MyHTMLElement { static get is() { return 'other-element'; } display(c) { return ''.repeat(c); } } customElements.define(MyOtherElement.is, MyOtherElement); Child class Base Class

Slide 99

Slide 99 text

class MyOtherElement extends MyHTMLElement { static get is() { return 'other-element'; } display(c) { return ''.repeat(c); } } customElements.define(MyOtherElement.is, MyOtherElement); Child class Override base class methods

Slide 100

Slide 100 text

([[counter]]) class MyOtherElement extends MyHTMLElement { static get is() { return 'other-element'; } static get template() { var t = Polymer.DomModule.import(this.is, 'template'); let superT = MyHTMLElement.cloneNode(true); } customElements.define(MyOtherElement.is, MyOtherElement); Child class Override base class template

Slide 101

Slide 101 text

([[counter]]) class MyOtherElement extends MyHTMLElement { static get is() { return 'other-element'; } static get template() { let t = Polymer.DomModule.import(MyOtherElement.is, 'template'); let superT = MyHTMLElement.template.cloneNode(true); return t.content.insertBefore(t.content.firstChild, superT); } } customElements.define(MyOtherElement.is, MyOtherElement); Child class Override base class template

Slide 102

Slide 102 text

POLYMER 2.0 HELPS ELEMENTS.

Slide 103

Slide 103 text

Slide 104

Slide 104 text

Slide 105

Slide 105 text

USE NO SUGAR.

Slide 106

Slide 106 text

Slide 107

Slide 107 text

Slide 108

Slide 108 text

Slide 109

Slide 109 text

USE INHERITANCE.

Slide 110

Slide 110 text

Slide 111

Slide 111 text

Slide 112

Slide 112 text

Slide 113

Slide 113 text

USE EVERYTHING.

Slide 114

Slide 114 text

POLYMER 2.0 HELPS APPS.

Slide 115

Slide 115 text

SHADOW STYLING FEELS TOO STRICT?

Slide 116

Slide 116 text

Just override! class MyHTMLElement extends Polymer.Element { static get is() { return 'my-element'; } attachDom(dom) { return this.attachShadow({mode:'open'}).appendChild(dom); } }

Slide 117

Slide 117 text

Just override! class MyHTMLElement extends Polymer.Element { static get is() { return 'my-element'; } attachDom(dom) { return this.appendChild(dom); } }

Slide 118

Slide 118 text

DEFINE ELEMENTS
 IN SCRIPT NOT 
 IMPORTS?

Slide 119

Slide 119 text

Just override! class MyHTMLElement extends Polymer.Element { static get is() { return 'my-element'; } static get template() { return ` … [[display(counter)]] ` } }

Slide 120

Slide 120 text

WHEN IN DOUBT JUST OVERRIDE.

Slide 121

Slide 121 text

WHEN YOU COME TO A FORK IN THE ROAD, TAKE IT. YOGI BERRA

Slide 122

Slide 122 text

Come say hi! +Monica Dinculescu @notwaldorf Icons: Gan Khoon Lay from Noun Project