rawnet lightning talk - web components

42
Web Components What happens next is unbelievable

Upload: rawnet

Post on 19-Feb-2017

108 views

Category:

Internet


5 download

TRANSCRIPT

Page 1: Rawnet Lightning Talk - Web Components

Web ComponentsWhat happens next is unbelievable

Page 2: Rawnet Lightning Talk - Web Components
Page 3: Rawnet Lightning Talk - Web Components
Page 4: Rawnet Lightning Talk - Web Components
Page 5: Rawnet Lightning Talk - Web Components

Design and Specification

Abstract intocomponents

Implement &Document

Plug & Play Component

Page 6: Rawnet Lightning Talk - Web Components

Asset Driven DevelopmentBreak designs down into a toolkit of components / blocks / modules /

layouts

Easier to test and fix bugs

DRY - Don’t Repeat Yourself

Reusable *

* ish

Page 7: Rawnet Lightning Talk - Web Components

ProblemsComponents can be influenced by context

Responsive Design

Documentation

Changing HTML

Tied to a back end technology or templating language

Process

Page 8: Rawnet Lightning Talk - Web Components

Components can be influenced by contextConflicting styles / scripts

BEM - .block__element--modifier

Data behaviour - <button data-behaviour=”js-awesomeness”>

Would be nicer to “seal” components

Page 9: Rawnet Lightning Talk - Web Components

Responsive DesignMedia queries are limited

Based on viewport

Step in the right direction

Only really useful for page-level layouts

Very rarely want a component to be influenced by viewport

Brittle

Page 10: Rawnet Lightning Talk - Web Components
Page 11: Rawnet Lightning Talk - Web Components

Responsive DesignMedia queries are limited

Based on viewport

Step in the right direction

Only really useful for page-level layouts

Very rarely want a component to be influenced by viewport

Brittle

Element / Container queries

Page 12: Rawnet Lightning Talk - Web Components
Page 13: Rawnet Lightning Talk - Web Components

Responsive DesignMedia queries are limited

Based on viewport

Step in the right direction

Only really useful for page-level layouts

Very rarely want a component to be influenced by viewport

Brittle

Element / Container queries

No CSS Specification

Use Cases & Requirements Document

Responsive Images Community Group

In draft

Main cause for contention is how to handle circularity

Long way off

JS Polyfills

Page 14: Rawnet Lightning Talk - Web Components

DocumentationStyleguide

More of a design thing

Asset LibraryFront End Frameworks - Bootstrap, Foundation

Page 15: Rawnet Lightning Talk - Web Components
Page 16: Rawnet Lightning Talk - Web Components

DocumentationStyleguide

More of a design thing

Asset LibraryFront End Frameworks - Bootstrap, Foundation

Copy & pasting HTML

What if HTML changes?

“Bootstrap for every client”

Writing decent documentation is time consuming

Dealing with changes / keeping up to date

Ideal situation is to automate as much of the process as possible

Page 17: Rawnet Lightning Talk - Web Components

“Bootstrap for every client”Hundreds of tools claim to do this

Sturgeon’s Law - 90% are shit

2 we’ve trialled:

Page 18: Rawnet Lightning Talk - Web Components

Tied to a back end or templating languagePHP

Concrete5

Symfony

Rails

There is a need for a pure front end - back end agnostic - solution

Page 19: Rawnet Lightning Talk - Web Components

Web ComponentsWhat happens next is unbelievable

Page 20: Rawnet Lightning Talk - Web Components

HTML Imports

4 new specifications

Shadow DOMCustom Elements

HTML Templates

Page 21: Rawnet Lightning Talk - Web Components

HTML ImportsInclude and reuse a HTML Document in a HTML Document

Block renderingBetter to concatenate multiple import files

Vulcanise - npm build tool

async attribute

Don’t block parsing

Automatically de-duplicates imports from same URL

Not the same as partials - have to use JS to get the contents of an import

Page 22: Rawnet Lightning Talk - Web Components

Accessing the content of an import with the link element’s .import propertywarnings.html index.html

Page 23: Rawnet Lightning Talk - Web Components

Javascript within an importBehaves just like a script tag with a defer attribute

Executes in the context of the importing document

JS within an import can access it’s own DOM and/or the DOM of the page that’s importing it

Scripts are executed in orderindex.html

component.html

Page 24: Rawnet Lightning Talk - Web Components

Allows you to bundle HTML/CSS/JS together into re-usable packages

Code organisation

Manage dependencies with automatic de-deduplication

Parallel HTML parsing

HTML Imports

Page 25: Rawnet Lightning Talk - Web Components

DOM-based, client-side templating

Allow you to declare chunks of reusable mark-up

Inert until activatedHidden DOM that doesn’t render

Scripts don’t run, images don’t load, etc

document.getElementById() won’t return child nodes of a template

Can be placed anywhere within <head> or <body>

HTML Templates

Page 26: Rawnet Lightning Talk - Web Components

Declaring and activating a template Declare using the new <template> tag

Activate by copying a template’s .content with document.importNode()

Page 27: Rawnet Lightning Talk - Web Components

Encapsulation

Hidden DOM within an element

Shadow DOM

Page 28: Rawnet Lightning Talk - Web Components

<video>

Page 29: Rawnet Lightning Talk - Web Components

Adds a new type of node than can be associated with an element

This node is called a shadow root

An element that has a shadow root is called a shadow host

Create Shadow DOM by invoking .createShadowRoot() on a DOM node

Shadow DOM

Page 30: Rawnet Lightning Talk - Web Components

Allows developers to extend the DOM and create new elements

We can be more expressive and give more meaning to our mark up

Bundle functionality together into a single tag

Extend the API of existing elements

Custom Elements

Page 31: Rawnet Lightning Talk - Web Components
Page 32: Rawnet Lightning Talk - Web Components

Allows developers to extend the DOM and create new elements

Custom Elements

We can be more expressive and give more meaning to our mark up

Bundle functionality together into a single tag

Extend the API of existing elements

Page 33: Rawnet Lightning Talk - Web Components

Elements are created using document.registerElement(tag-name, prototype)

Tag names must contain a dash

prototype argument is optional; custom elements inherit from HTMLELement by default

Calling document.registerElement() tells the browser about your new element and returns a constructor that can be used to create instances of your element

Registering a new element

Page 34: Rawnet Lightning Talk - Web Components

To extend a native HTML element create a new element that inherits the prototype of the element you want to extend

Extending an existing element

Page 35: Rawnet Lightning Talk - Web Components

GitHub example

time is used as base element

datetime attribute provides an absolute date/time

relative-time is specified as type extension

TextContent shows the relative date/time

Page 36: Rawnet Lightning Talk - Web Components

HTML Imports

Shadow DOMCustom Elements

HTML Templates

Page 37: Rawnet Lightning Talk - Web Components

Not quite!

Page 38: Rawnet Lightning Talk - Web Components
Page 39: Rawnet Lightning Talk - Web Components

HTML Imports

Shadow DOM

Custom ElementsHTML Templates

Supported

In development

Under consideration

Not interested

Page 40: Rawnet Lightning Talk - Web Components

PolymerX-Tag BosonicSmall library for creating

custom elements

IE9+

All web components specs

Adds features like two-way data binding and property observation

Large library of pre-built components

IE10+

All web components specs

Includes a handful of basic elements like tabs

IE9+

Page 41: Rawnet Lightning Talk - Web Components

HTML Imports

Shadow DOMCustom Elements

HTML Templates

Page 42: Rawnet Lightning Talk - Web Components