polymer vs other libraries (devfest ukraine 2015)

32
Other libraries Polymer vs Jakub Škvára Full-stack Engineer @ Shipito

Upload: jskvara

Post on 20-Mar-2017

2.650 views

Category:

Software


0 download

TRANSCRIPT

Page 1: Polymer vs other libraries (Devfest Ukraine 2015)

Other libraries

Polymer vs

Jakub ŠkváraFull-stack Engineer @ Shipito

Page 2: Polymer vs other libraries (Devfest Ukraine 2015)

Polymer“jQuery for web components”

Page 3: Polymer vs other libraries (Devfest Ukraine 2015)

#dfua

Polymer - use your own HTML elements

<head><html> <!-- Import element --> <link rel="import" href="components/google-map/google-map.html">

</head><body>

<!-- Use element --> <google-map latitude="50.066354" longitude="14.402736" zoom="14.402736"></google-map>

Page 4: Polymer vs other libraries (Devfest Ukraine 2015)

#dfua

Polymer element

<dom-module id="my-element">

<link rel="import" type="css" href="my-element.css">

<template>

<p>My element</p>

</template>

<script>

Polymer({

is: 'my-element'

});

</script>

</dom-module>

Page 5: Polymer vs other libraries (Devfest Ukraine 2015)

Components benefits

Page 6: Polymer vs other libraries (Devfest Ukraine 2015)

#dfua

Encapsulation

Page 7: Polymer vs other libraries (Devfest Ukraine 2015)

#dfua

Configuration

Page 8: Polymer vs other libraries (Devfest Ukraine 2015)

#dfua

Composable

Page 9: Polymer vs other libraries (Devfest Ukraine 2015)

#dfua

Decoupling

Page 10: Polymer vs other libraries (Devfest Ukraine 2015)

Polymer advantages

Page 11: Polymer vs other libraries (Devfest Ukraine 2015)

#dfua

Speed of development

Page 12: Polymer vs other libraries (Devfest Ukraine 2015)

#dfua

Rich forms

Page 13: Polymer vs other libraries (Devfest Ukraine 2015)

#dfua

Special elements

Page 14: Polymer vs other libraries (Devfest Ukraine 2015)

#dfua

Material design

Page 15: Polymer vs other libraries (Devfest Ukraine 2015)

Angular vs Polymer vs React

Page 16: Polymer vs other libraries (Devfest Ukraine 2015)

#dfua

Angular Directives

angular.module('helloWorldDirective', [])

.controller('Controller', ['$scope', function($scope) {

$scope.hello = {who: 'Devfest'};

}])

.directive('myHelloWorld', function() {

return {

template: 'Hello {{hello.who}}'

};

});

<div ng-controller="Controller">

<my-hello-world></my-hello-world>

</div>

Page 17: Polymer vs other libraries (Devfest Ukraine 2015)

#dfua

Angular vs Polymer

● MVC Framework

● $scope

● Angular template system

● View Library

● encapsulation (Shadow DOM)

● W3C standards + Polyfills

Page 18: Polymer vs other libraries (Devfest Ukraine 2015)

#dfua

● Angular 2.0 directives - same as Polymer Web Components● Different binding system○ Changes from Polymer don’t push changes to Angular○ bindPolymer and ng-polymer-elements directives for

Angular

Angular + Polymer

<input type="text" ng-model="text"/>

<input is="iron-input" ng-model="text"/>

<paper-input ng-model="text""></paper-input>

Page 19: Polymer vs other libraries (Devfest Ukraine 2015)

#dfua

React Components

var HelloWorld = React.createClass({

render: function() {

return (

<div className="helloWorld">

Hello {this.props.who}!

</div>

);

}

});

ReactDOM.render(

<HelloWorld who="Lviv" />,

document.getElementById('content')

);

Page 20: Polymer vs other libraries (Devfest Ukraine 2015)

#dfua

React vs Polymer

● Virtual DOM

● Server-side rendering

● One-way data flow

● Custom Elements

● Portability

● Two-way data binding

Page 21: Polymer vs other libraries (Devfest Ukraine 2015)

#dfua

● Render Web Components with React● react-polymer library○ https://github.com/jscissr/react-polymer

React + Polymer

import polymerReact from 'polymer-react';

import React from 'react';

import {PaperInput} from 'polymer-react/input';

<PaperInput value={this.state.value} onChange={this.valueChanged} />

Page 22: Polymer vs other libraries (Devfest Ukraine 2015)

Angular Polymer React

Page 23: Polymer vs other libraries (Devfest Ukraine 2015)

#dfua

DOM

Shadow DOMNormal DOM Virtual DOM

Page 24: Polymer vs other libraries (Devfest Ukraine 2015)

#dfua

DOM updates

Observefunctions that

manipulate the DOM

$watch Tree comparison

Page 25: Polymer vs other libraries (Devfest Ukraine 2015)

#dfua

CSS

Component stylesCSS styles Page or inline Styles

Page 26: Polymer vs other libraries (Devfest Ukraine 2015)

#dfua

Template

<template>HTML string, <script> or external file

JSX

Page 27: Polymer vs other libraries (Devfest Ukraine 2015)

#dfua

Content

<content>Transclusion props.children

Page 28: Polymer vs other libraries (Devfest Ukraine 2015)

#dfua

Data binding

Two-wayOne-way

Object.observe()

Two-wayOne-way$watch

One-way(Flux)

Page 29: Polymer vs other libraries (Devfest Ukraine 2015)

#dfua

Life cycle

Asynchronous (Created, Ready)

Synchronous (compile + link)

Mount + update

Page 30: Polymer vs other libraries (Devfest Ukraine 2015)

Let’s try polymer with your current framework

Page 31: Polymer vs other libraries (Devfest Ukraine 2015)

Workshop: Let's build a new Polymer applicationTomorrow 16:00Community hall

Page 32: Polymer vs other libraries (Devfest Ukraine 2015)

Thank you!Questions?Questions?

@skvaros+JakubSkvarawww.jakubskvara.cz