Slide 1

Slide 1 text

Let’s start the Web Components k-kuwahara @kuwahara_jsri @clown0082 Oct 30, 2018 ʲαϙʔλʔζCoLabษڧձʳ

Slide 2

Slide 2 text

About me const my_info = { Workplace: ‘Yumemi Inc’, Community: ‘Riot.js, Ionic, DIST’, Favorites: ‘npm k-kuwahara ’, PokemonGO: ‘TL38’ }

Slide 3

Slide 3 text

github.com/riot

Slide 4

Slide 4 text

Sorry... # Because of time, I don’t mention all the grammar of JavaScript.

Slide 5

Slide 5 text

⚠Attention⚠ We verified this slide with Google Chrome. Please check other browsers by yourself.

Slide 6

Slide 6 text

What is “Web Components” ? How to program Custom Elements Shadow DOM ES Modules Practical usage Agenda

Slide 7

Slide 7 text

What is Web Components?

Slide 8

Slide 8 text

…before that

Slide 9

Slide 9 text

A bit of background

Slide 10

Slide 10 text

Component-oriented framework of JavaScript

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

⚙ ⚙

Slide 13

Slide 13 text

⚙ ⚙ ❌

Slide 14

Slide 14 text

Is there something that doesn’t depend on any libraries?

Slide 15

Slide 15 text

any ⚙ ⚙ ⚙ ⚙

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

What is “Web Components” ?

Slide 18

Slide 18 text

No content

Slide 19

Slide 19 text

Works on “modern” browser

Slide 20

Slide 20 text

No libraries required ❗ No packages required ❗ No modules required ❗

Slide 21

Slide 21 text

No libraries required ❗ No packages required ❗ No modules required ❗ It doesn’t depend on tools or libraries

Slide 22

Slide 22 text

ɹ Header Footer Navigation Bars (13 menus) Margen Sub Condition1 (list) Sub Condition2 (list) Main Condition2 (list) Main Condition3 (list) Main Condition1 (list)

Slide 23

Slide 23 text

ɹ Header Footer Navigation Bars (13 menus) Margen Sub Condition1 (list) Sub Condition2 (list) Main Condition2 (list) Main Condition3 (list) Main Condition1 (list)

Slide 24

Slide 24 text

ɹ Header Footer Navigation Bars (13 menus) Margen Sub Condition1 (list) Sub Condition2 (list) Main Condition2 (list) Main Condition3 (list) Main Condition1 (list) Scope works (so-called encapsulation)

Slide 25

Slide 25 text

How to program

Slide 26

Slide 26 text

Web Components is based on three specifications.

Slide 27

Slide 27 text

Custom Elements Shadow DOM ES Modules Three specifications ※ HTML Imports

Slide 28

Slide 28 text

HTML Imports ?

Slide 29

Slide 29 text

⚠Attention⚠ “HTML Imports” is deprecate and will remove

Slide 30

Slide 30 text

1. Custom Elements

Slide 31

Slide 31 text

Custom Elements is a function for creating your own custom HTML elements. Custom Elements can have its own script action and CSS styling. This is part of web components, but you can use it alone. Custom Elements see also: https://developer.mozilla.org/ja/docs/Web/Web_Components/Custom_Elements

Slide 32

Slide 32 text

No content

Slide 33

Slide 33 text

custom elements, name is “-” required inheritance of HTMLElement class is required

Slide 34

Slide 34 text

lifecycle methods

Slide 35

Slide 35 text

constructor() connectedCallback() disconnectedCallback() attributeChangedCallback(attributeName, oldValue, newValue, namespace) adoptedCallback(oldDocument, newDocument) lifecycle callbacks

Slide 36

Slide 36 text

constructor() connectedCallback() disconnectedCallback() attributeChangedCallback(attributeName, oldValue, newValue, namespace) adoptedCallback(oldDocument, newDocument) lifecycle callbacks Invoked when the custom element is created or updated.

Slide 37

Slide 37 text

constructor() connectedCallback() disconnectedCallback() attributeChangedCallback(attributeName, oldValue, newValue, namespace) adoptedCallback(oldDocument, newDocument) lifecycle callbacks Invoked each time the custom element is appended into HTML document.

Slide 38

Slide 38 text

constructor() connectedCallback() disconnectedCallback() attributeChangedCallback(attributeName, oldValue, newValue, namespace) adoptedCallback(oldDocument, newDocument) lifecycle callbacks Invoked each time the custom element is disconnected from the document's DOM.

Slide 39

Slide 39 text

constructor() connectedCallback() disconnectedCallback() attributeChangedCallback(attributeName, oldValue, newValue, namespace) adoptedCallback(oldDocument, newDocument) lifecycle callbacks Invoked each time the custom element is moved to a new HTML document.

Slide 40

Slide 40 text

constructor() connectedCallback() disconnectedCallback() attributeChangedCallback(attributeName, oldValue, newValue, namespace) adoptedCallback(oldDocument, newDocument) lifecycle callbacks Invoked each time one of the custom element's attributes is added, removed, or changed.

Slide 41

Slide 41 text

constructor() connectedCallback() disconnectedCallback() attributeChangedCallback(attributeName, oldValue, newValue, namespace) adoptedCallback(oldDocument, newDocument) lifecycle callbacks ※Which attributes to notice change for is specified in a static get observedAttributes method

Slide 42

Slide 42 text

No content

Slide 43

Slide 43 text

define the name of the attribute you want to monitor

Slide 44

Slide 44 text

It must be returned as an array of strings

Slide 45

Slide 45 text

using getter/setter

Slide 46

Slide 46 text

Will not DOM be drawn without being styled depending on the drawing timing ?

Slide 47

Slide 47 text

No content

Slide 48

Slide 48 text

whenDefined method is return “Promise”

Slide 49

Slide 49 text

2. Shadow DOM

Slide 50

Slide 50 text

The ShadowRoot interface of the Shadow DOM API is the root node of a DOM subtree that is rendered separately from a document's main DOM tree. Shadow DOM see also: https://developer.mozilla.org/ja/docs/Web/API/ShadowRoot

Slide 51

Slide 51 text

No content

Slide 52

Slide 52 text

Encapsulation !!

Slide 53

Slide 53 text

No content

Slide 54

Slide 54 text

How to create Shadow DOM

Slide 55

Slide 55 text

No content

Slide 56

Slide 56 text

Element.attachShadow method creates Shadow DOM

Slide 57

Slide 57 text

Unless there is a particular reason, in “open” mode

Slide 58

Slide 58 text

Shadow DOM styling

Slide 59

Slide 59 text

:host() :host-content() ::slotted() Shadow DOM styling

Slide 60

Slide 60 text

3. ES Modules

Slide 61

Slide 61 text

See this link↓↓ https://developer.mozilla.org/ja/docs/Web/ JavaScript/Reference/Statements/import Sorry…

Slide 62

Slide 62 text

Browser compatibility

Slide 63

Slide 63 text

image by: https://caniuse.com/#search=custom%20elements

Slide 64

Slide 64 text

image by: https://caniuse.com/#search=shadow%20dom

Slide 65

Slide 65 text

image by: https://caniuse.com/#search=modules

Slide 66

Slide 66 text

Practical usage

Slide 67

Slide 67 text

Use “lit-html” Use “Polymer” Use “webcomponents.js” Combine with other UI libraries Practical usage

Slide 68

Slide 68 text

Web Components for future change, migration Standardize and coexist with other frameworks In the end

Slide 69

Slide 69 text

Have fun with Web Components!!

Slide 70

Slide 70 text

Publicity

Slide 71

Slide 71 text

We’re looking for Engineers!!

Slide 72

Slide 72 text

No content

Slide 73

Slide 73 text

No content