Webcomponents TLV October 2014

70
Web components Dmitry Bakaleinik [email protected] @demongloom October 2014

description

Web components lecture be Dmitry Bakaleinik

Transcript of Webcomponents TLV October 2014

Page 1: Webcomponents TLV October 2014

Web components

Dmitry����������� ������������������  Bakaleinik����������� ������������������  [email protected]����������� ������������������  @demongloom

October����������� ������������������  2014

Page 2: Webcomponents TLV October 2014

HTML was very lean, with very basic data display and entry. It was clear which was better.It could be mastered by people who were not good programmers — or even programmers at all. You could make something that looked "OK" pretty quickly.

Web in 1990s, HTML pages were lean and simple

HTML and the World Wide Web started in the early 1990's. Version 1.0 of the first popular, dominant commercial browser, Netscape Navigator, was released in December 1994. It supported very simple HTML, which included simple styling and simple forms for data entry. Later versions in 1995 added tables, cookies, and very early JavaScript. Microsoft released its first browser in 1995.At this point, extremely rich applications could be written in C++, Visual Basic, or any of many programming systems.

Page 3: Webcomponents TLV October 2014

The HTML could be mastered by people who were

not good programmers or even programmers at all

Page 4: Webcomponents TLV October 2014

You could make something that looked "OK" pretty quickly

Page 5: Webcomponents TLV October 2014
Page 6: Webcomponents TLV October 2014

HTML Elements are encapsulated

Page 7: Webcomponents TLV October 2014

HTML Elements are configurable

Page 8: Webcomponents TLV October 2014

Even more configuration!

Page 9: Webcomponents TLV October 2014

HTML Elements composition

Page 10: Webcomponents TLV October 2014

HTML Elements are programmable

Page 11: Webcomponents TLV October 2014

jQuery

Mootools

Prototype

Dojo

ExtJS

Web in 2000s, rapid growth of UI frameworks

Backbone

AngularJS

Page 12: Webcomponents TLV October 2014

JavaScript dominates the web’s programming

landscape.

Page 13: Webcomponents TLV October 2014

Instead writing HTML, we’re writing more

JavaScript.

Page 14: Webcomponents TLV October 2014

What is broken in the web today?

Page 15: Webcomponents TLV October 2014

Tabs:����������� ������������������  a����������� ������������������  common����������� ������������������  component����������� ������������������  on����������� ������������������  the����������� ������������������  web

Page 16: Webcomponents TLV October 2014

Dojo

Page 17: Webcomponents TLV October 2014

Backbone

Page 18: Webcomponents TLV October 2014

Ember

Ember

Page 19: Webcomponents TLV October 2014

ExtJS

ExtJS

Page 20: Webcomponents TLV October 2014

Angular

Page 22: Webcomponents TLV October 2014

Our HTML is terrible

Page 23: Webcomponents TLV October 2014
Page 24: Webcomponents TLV October 2014

Our HTML is terrible

Page 25: Webcomponents TLV October 2014
Page 26: Webcomponents TLV October 2014

Our HTML is terrible

Page 27: Webcomponents TLV October 2014
Page 28: Webcomponents TLV October 2014
Page 29: Webcomponents TLV October 2014
Page 30: Webcomponents TLV October 2014

Can we do better?

Page 31: Webcomponents TLV October 2014

Back to HTML

Page 32: Webcomponents TLV October 2014

What we’re used before

Page 33: Webcomponents TLV October 2014

Why not just mega-button?

Page 34: Webcomponents TLV October 2014

The component model for Web

CustomElements

HTMLTemplates

HTMLImports

ShadowDOM

Let authors define their own elements, with new tag names and new script interfaces.

Defines how templates and custom elements are packaged and loaded as a resource.

Define chunks of markup that are inert but can be activated for use later.

Page 35: Webcomponents TLV October 2014

Web components are set of emerging standards

that allow developers to extend html

Page 36: Webcomponents TLV October 2014

Can I use web components?

Templates ✓ ✓ ✓ ✗ ✗

Shadow DOM ✓ ✓ ✗ ✓ ✗

Custom Elements ✓ ✓ ✓ ✗ ✗

Imports ✓ ✓ ✗ ✗ ✗

Page 37: Webcomponents TLV October 2014

New web technology detection easy way

• Try it out on Internet Explorer

• Did it work?

• No?

• It’s a new web technology

Page 38: Webcomponents TLV October 2014

Let authors define their own elements, with new tag names and new script interfaces.

Custom Elements

Page 39: Webcomponents TLV October 2014

Defining custom element

The����������� ������������������  name����������� ������������������  must����������� ������������������  contain����������� ������������������  a����������� ������������������  dash����������� ������������������  (-)

Page 40: Webcomponents TLV October 2014

Extending custom element

Page 42: Webcomponents TLV October 2014

Observe attribute changes

Page 43: Webcomponents TLV October 2014

Styling custom element

no����������� ������������������  dot����������� ������������������  ����������� ������������������  in����������� ������������������  selector

Page 45: Webcomponents TLV October 2014

Defines how templates and custom elements are packaged and loaded as a resource.

HTML Imports

Page 46: Webcomponents TLV October 2014

Custom element html filemega-button.html

Page 47: Webcomponents TLV October 2014

Importing custom element

Page 48: Webcomponents TLV October 2014
Page 49: Webcomponents TLV October 2014

Detecting broken elements

Page 50: Webcomponents TLV October 2014

Define chunks of markup that are inertbut can be activated for use later.

Template

Page 51: Webcomponents TLV October 2014

The <template> element declares fragments of HTML that can be cloned and inserted

by script

Page 52: Webcomponents TLV October 2014

In a rendering, the template element represents nothing

Page 53: Webcomponents TLV October 2014

Template declaration

Page 55: Webcomponents TLV October 2014

Encapsulates a DOM subtree for more reliable composition of user interface elements.

Shadow DOM

Page 56: Webcomponents TLV October 2014

The fundamental problem that makes widgets built out of

HTML and JavaScript hard to use:

Page 57: Webcomponents TLV October 2014

The DOM tree inside a widget isn’t encapsulated from

the rest of the page

Page 58: Webcomponents TLV October 2014
Page 59: Webcomponents TLV October 2014

This lack of encapsulation means your document stylesheet might

accidentally apply to parts inside the widget

Page 60: Webcomponents TLV October 2014

Your JavaScript might accidentally modify

parts inside the widget

Page 61: Webcomponents TLV October 2014

Your IDs might overlap with IDs

inside the widget and so on

Page 62: Webcomponents TLV October 2014

Shadow DOM addresses the DOM tree

encapsulation problem

Page 63: Webcomponents TLV October 2014

With Shadow DOM, elements can get a new kind of node

associated with them

Page 64: Webcomponents TLV October 2014

This new kind of node is called a shadow root

Page 65: Webcomponents TLV October 2014

An element that has a shadow root associated with it is called a shadow host

Page 66: Webcomponents TLV October 2014

The content of a shadow host isn’t rendered; the content of the shadow root is rendered instead

Page 67: Webcomponents TLV October 2014

The content of a shadow host isn’t rendered; the content of the shadow root is rendered instead

Page 68: Webcomponents TLV October 2014
Page 70: Webcomponents TLV October 2014

Thanks!