booting up with polymer

51
Booting up with Polymer

Upload: marcus-hellberg

Post on 08-Jan-2017

258 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Booting up with polymer

Booting up with Polymer

Page 2: Booting up with polymer

Why Web Components?

Page 3: Booting up with polymer
Page 4: Booting up with polymer
Page 6: Booting up with polymer
Page 7: Booting up with polymer

4 standards

• Custom elements

• HTML Imports

• Templates

• Shadow DOM

Page 8: Booting up with polymer
Page 9: Booting up with polymer

Do browsers support this?

Page 10: Booting up with polymer

Source: webcomponents.org

Page 11: Booting up with polymer

webcomponents.js

now also available as lite!

Page 12: Booting up with polymer

What is Polymer then?

• Helper library for building Web Components – nothing more

• Comes with a collection of ready made Web Components

Page 13: Booting up with polymer

Building apps with Polymer

Page 14: Booting up with polymer

Do we need a framework?

Page 15: Booting up with polymer

... the DOM is the framework

• Component model (= HTML elements)

• Data flow (= attributes, properties and events)

• Declarative format (= HTML)

• Now also extensible through Web Components

Page 16: Booting up with polymer

Building apps out of components

• Composition

• Encapsulation

• Mediator pattern

Business logic

API API

APIcomponent

child 1 child 2

Page 17: Booting up with polymer

<text-repeater text="Hello"></text-repeater>

Page 18: Booting up with polymer
Page 19: Booting up with polymer

<link rel="import" href="bower_components/paper-input/paper-input.html">

<dom-module id="text-repeater"> <template> <paper-input value="{{text}}"></paper-input> <b>You wrote: </b> <span>[[text]]</span> </template> <script> Polymer({ is: 'text-repeater', properties: { text: String } }); </script> </dom-module>

text-repeater.html

Page 20: Booting up with polymer

All code in one file?!

Page 21: Booting up with polymer

<template> <paper-input value="{{text}}"></paper-input> <b>You wrote: </b> <span>[[text]]</span></template>

<script> Polymer({ is: 'web-component', properties: { text: String } }); </script>

Business logic

API API

APItext-repeater

paper-input span

<text-repeater text="Hello"></text-repeater>

Page 23: Booting up with polymer

properties: { token: { type: String, notify: true, value: '' }, selected: { type: Number, notify: true, computed: '_selectPage(token)' } },

listeners: { 'iron-form-response': '_handleLoginSuccess', 'iron-form-error': '_handleLoginError'},

observers: ['_fetchStuff(token, other)']

Page 24: Booting up with polymer

Let's get started.

Page 25: Booting up with polymer

Backend

Page 26: Booting up with polymer

Spring Boot

Takes an opinionated view of building production-ready Spring applications. Spring Boot favors convention over configuration and is designed to get you up and running as quickly as possible.

Page 27: Booting up with polymer

• Create stand-alone Spring applications

• Embed Tomcat, Jetty or Undertow directly (no need to deploy WAR files)

• Provide opinionated 'starter' POMs to simplify your Maven configuration

• Automatically configure Spring whenever possible

• Provide production-ready features such as metrics, health checks and externalized configuration

• Absolutely no code generation and no requirement for XML configuration

projects.spring.io/spring-boot

Page 28: Booting up with polymer

start.spring.io

Page 29: Booting up with polymer

Token authentication

• JSON Web Token

• Compact

• Self-contained

•header.payload.signature

Page 30: Booting up with polymer

JWT authentication

Client Server

1. Login request (username/password)

2. JWT gets returned to browser Authenticate, create JWT

3. Request, token in header

4. Response Validate token

Page 31: Booting up with polymer
Page 32: Booting up with polymer

Polymer app

Page 33: Booting up with polymer

Some additional tools we'll use

• npm – development time JS dependencies

• bower – Polymer dependencies

• gulp – JS based build tool used to run some optimization tasks

• Integrated into Maven build process

Page 34: Booting up with polymer

server

<summary-panel>

<login-page>

<expenses-editor>

<expense-application>

<expenses-page>

<expenses-list>

Page 35: Booting up with polymer
Page 36: Booting up with polymer

What about performance?

Page 37: Booting up with polymer
Page 38: Booting up with polymer

Optimizing

• vulcanize – combine all imports into one file

• crisper – pull out all JS into separate file for CSP compliance

• htmlmin & uglify – minimize assets

• turn on server gzip

Page 39: Booting up with polymer

gulp.task('build', function() { return gulp .src(SRC_DIR + '/elements.html') .pipe($.vulcanize({ inlineScripts: true, inlineCss: true })) .pipe($.crisper()) .pipe($.if('*.js', $.uglify({ preserveComments: 'some' }))) .pipe($.if('*.html', $.htmlmin({ customAttrAssign: [/\$=/], removeComments: true, collapseWhitespace: true }))) .pipe(gulp.dest(DEST_DIR)); });

Page 40: Booting up with polymer

mvncleanpackage-Pproduction

Page 41: Booting up with polymer

Optimizing some more

• Load imports asynchronously

• Style "app skeleton"

• Use native shadow DOM where available

Page 42: Booting up with polymer
Page 43: Booting up with polymer
Page 44: Booting up with polymer

80% smaller and faster startup

Page 45: Booting up with polymer

Ready for production?

Page 46: Booting up with polymer

Getting started with

Page 49: Booting up with polymer

github.com/vaadin-marcus/polymer-spring-boot

Page 50: Booting up with polymer

?!

Page 51: Booting up with polymer

thanks!

@marcushellberg (twitter) @marcus (polymer slack)