web components - steven skelton's...

23
Reactive Programming Toronto December 3, 2014 Web Components Reactive Architecture for the Front End Steven Skelton

Upload: others

Post on 30-May-2020

8 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Web Components - Steven Skelton's Blogstevenskelton.ca/files/2014/12/reactive_web_components.pdf · Web Components Reactive Architecture for the Front End Steven Skelton. Reactive

Reactive Programming TorontoDecember 3, 2014

Web ComponentsReactive Architecture for the Front End

Steven Skelton

Page 2: Web Components - Steven Skelton's Blogstevenskelton.ca/files/2014/12/reactive_web_components.pdf · Web Components Reactive Architecture for the Front End Steven Skelton. Reactive

Reactive Manifesto

Is a pattern for building software capable of handling today's application requirements:

● Highly responsive to user,● Large amounts of data,● Grow and adapt to change

Sounds like it could also apply to the front-end.....

Page 3: Web Components - Steven Skelton's Blogstevenskelton.ca/files/2014/12/reactive_web_components.pdf · Web Components Reactive Architecture for the Front End Steven Skelton. Reactive

Reactive System Strategy

Responsive

Resilient

Message Driven

Elastic

Responsive

Message Driven

Elastic Resilient

Page 4: Web Components - Steven Skelton's Blogstevenskelton.ca/files/2014/12/reactive_web_components.pdf · Web Components Reactive Architecture for the Front End Steven Skelton. Reactive

Reactive Analogue

Server Cluster

● Responsive

● Elastic

● Resilient

● Message Driven

Web Page

● Responsive

● Consistently Fast UI?

● Less bugs in SDLC?

● Rethink Event Bindings?

Aggregate → Single

Page 5: Web Components - Steven Skelton's Blogstevenskelton.ca/files/2014/12/reactive_web_components.pdf · Web Components Reactive Architecture for the Front End Steven Skelton. Reactive

“Elastic” Browser Performance

Today websites handle more data, with rich interactions, all within a single page.

Each page requires:● more JS libraries,● larger downloads,● data-binding,● dynamic DOM.

Leading to too-many, bizarre, frameworks.

Page 6: Web Components - Steven Skelton's Blogstevenskelton.ca/files/2014/12/reactive_web_components.pdf · Web Components Reactive Architecture for the Front End Steven Skelton. Reactive

Exponential Problem

Today's frameworks bend around browser limitations

They work...for small data sets or a limited number of instances.

AngularJS Dirty Checking

Page 7: Web Components - Steven Skelton's Blogstevenskelton.ca/files/2014/12/reactive_web_components.pdf · Web Components Reactive Architecture for the Front End Steven Skelton. Reactive

New JavaScript Features that Scale

Native Browser support(No download, No JavaScript engine)

– DOM Mutation Observers

– JavaScript Object observers

– <template>

Multi-threading– Web workers: Separate computations and UI

– async loading and parsing

Page 8: Web Components - Steven Skelton's Blogstevenskelton.ca/files/2014/12/reactive_web_components.pdf · Web Components Reactive Architecture for the Front End Steven Skelton. Reactive

“Resilient” Webpages

Fewer errors by simplifying code● HTML is the final product,● Impedance mismatch of complex frameworks.

Increase composibility, reusability of components● Dev teams work more efficiently,● Less work required,● More cohesive design.

Page 9: Web Components - Steven Skelton's Blogstevenskelton.ca/files/2014/12/reactive_web_components.pdf · Web Components Reactive Architecture for the Front End Steven Skelton. Reactive

Slimmer Frameworks, Expand HTML

Native support for Custom HTML tags ● Familiar, reusable components,● No external dependencies,● Built using HTML DOM in a <template>.

Replaces frameworks' abstractions:● None are framework agnostic,● Rely on string, JSON or non-HTML templates.

Page 10: Web Components - Steven Skelton's Blogstevenskelton.ca/files/2014/12/reactive_web_components.pdf · Web Components Reactive Architecture for the Front End Steven Skelton. Reactive

Shadow DOM

Enforces proper scoping,● Segregate HTML along bounded contexts,

– Encapsulation of internals,

– Guard against external CSS, Id naming conflicts,

– Restrict interactions to messages.

Ensures Loose-coupling, Reusability

Can be pierced unlike an iframe when necessary

Page 11: Web Components - Steven Skelton's Blogstevenskelton.ca/files/2014/12/reactive_web_components.pdf · Web Components Reactive Architecture for the Front End Steven Skelton. Reactive

Web Components

Native Browser Support(polyfilled if not yet supported)

● Custom HTML Elements● <template>

● Shadow DOM● Object.observe

● HTML Imports

Page 12: Web Components - Steven Skelton's Blogstevenskelton.ca/files/2014/12/reactive_web_components.pdf · Web Components Reactive Architecture for the Front End Steven Skelton. Reactive

Polymer

Native browser implementations are low-level and un-opinionated, Polymer is the first library to put it all together.

Still pre-release, version 1.0 scheduled for Q2

Already used in production at:Salesforce, News Corp, GitHub, YouTube, Google

(active development at Google)

Page 13: Web Components - Steven Skelton's Blogstevenskelton.ca/files/2014/12/reactive_web_components.pdf · Web Components Reactive Architecture for the Front End Steven Skelton. Reactive

BE Reactive System Strategy

Responsive

Resilient

Message Driven

Elastic

Responsive

Message Driven

Elastic Resilient

Page 14: Web Components - Steven Skelton's Blogstevenskelton.ca/files/2014/12/reactive_web_components.pdf · Web Components Reactive Architecture for the Front End Steven Skelton. Reactive

FE Reactive System Strategy

Responsive

Resilient

Message Driven

Elastic

Responsive

Directed Event Bindings?(Message Driven)

Native Support(elastic)

Expanded HTML(Resilient)

Page 15: Web Components - Steven Skelton's Blogstevenskelton.ca/files/2014/12/reactive_web_components.pdf · Web Components Reactive Architecture for the Front End Steven Skelton. Reactive

Message vs. Event System

● Difference very small in a FE context

● Ideal system:– Message-oriented middleware,

– Event-driven components,

– Non-blocking execution.

Message-driven: focus on recipients,

Event-driven: focus on sources.

Page 16: Web Components - Steven Skelton's Blogstevenskelton.ca/files/2014/12/reactive_web_components.pdf · Web Components Reactive Architecture for the Front End Steven Skelton. Reactive

Message Delivery via 2-Way Bindings

<h1>Welcome back {{account.name}}!</h1>

<song-search genres="{{account.genres}}" results="{{playlist}}"></song-search>

<media-player playlist="{{playlist}}"></media-player>

<div class="footer"> <account-profile account="{{account}}"> </account-profile></div>

Page 17: Web Components - Steven Skelton's Blogstevenskelton.ca/files/2014/12/reactive_web_components.pdf · Web Components Reactive Architecture for the Front End Steven Skelton. Reactive

observe

Polymer expressions and filters can be used to transform and combine data outside of components:

● Data references act as middleware,● Location transparency,● Components do not require knowledge of

external events, maintaining loose coupling.

{{ a + b | base16 }}

{{ myNumbers | gt(3) | sort }}

Page 18: Web Components - Steven Skelton's Blogstevenskelton.ca/files/2014/12/reactive_web_components.pdf · Web Components Reactive Architecture for the Front End Steven Skelton. Reactive

Object.observe(), Array.observe()

Events when:● the value of a data property is updated,● any property is added,● any property is deleted,● any property is reconfigured.

No expensive dirty-checking, no special methods.

Plain Old JavaScript Objects.

Page 19: Web Components - Steven Skelton's Blogstevenskelton.ca/files/2014/12/reactive_web_components.pdf · Web Components Reactive Architecture for the Front End Steven Skelton. Reactive

High level observe libraries

observe.js● PathObserver, ArrayObserver, ObjectObserver,

CompoundObserver, ObserverTransform

watchtower.js● Angular 2.0's change detection● Undocumented, more complex

Both can Polyfill with dirty-checking

Page 20: Web Components - Steven Skelton's Blogstevenskelton.ca/files/2014/12/reactive_web_components.pdf · Web Components Reactive Architecture for the Front End Steven Skelton. Reactive

Reactive Analogue

Server Cluster

● Responsive

● Elastic

● Resilient

● Message Driven

Web Page

● Responsive

● Native Support,Multi-threaded

● Loose Coupling, Encapsulation

● Event Driven Messages

Aggregate → Single

Page 21: Web Components - Steven Skelton's Blogstevenskelton.ca/files/2014/12/reactive_web_components.pdf · Web Components Reactive Architecture for the Front End Steven Skelton. Reactive

Strategies for a Reactive FE

Server Cluster

● Responsive

● Elastic

● Resilient

● Message Driven

Web Page

● Responsive

● Native Support,Web Workers

● Shadow DOM,Custom Elements

● Object.observe

Aggregate → Single

Page 22: Web Components - Steven Skelton's Blogstevenskelton.ca/files/2014/12/reactive_web_components.pdf · Web Components Reactive Architecture for the Front End Steven Skelton. Reactive

Web Component Resources

● polymer-project.org

● HTML5Rocks.com

● customelements.io

● component.kitchen

● W3C Web Components wiki

● YouTube:

- Chrome Dev Summit, Google I/O, JSConf

Page 23: Web Components - Steven Skelton's Blogstevenskelton.ca/files/2014/12/reactive_web_components.pdf · Web Components Reactive Architecture for the Front End Steven Skelton. Reactive

Thanks for Listening!

Questions ?

https://github.com/stevenrskelton– Various Polymer web components

Blog: http://stevenskelton.ca