Top Banner
Polymer Jakub Škvára @skvaros Dev Fest Kraków 2014
16

Polymer Code Lab in Dart - DevFest Kraków 2014

Jul 02, 2015

Download

Software

jskvara

Polymer Code Lab in Dart from DevFest Kraków 2014
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Polymer Code Lab in Dart - DevFest Kraków 2014

Polymer

Jakub Škvára@skvaros

Dev Fest Kraków 2014

Page 2: Polymer Code Lab in Dart - DevFest Kraków 2014
Page 3: Polymer Code Lab in Dart - DevFest Kraków 2014

What is polymer

Polymer is a new type of library for the web, built on top of Web

Components, and designed to leverage the evolving web platform

on modern browsers.

Page 4: Polymer Code Lab in Dart - DevFest Kraków 2014

Web Components● Custom elements: <my-element></my-element>● Shadow dom: (better <iframe>)● HTML Imports: <link rel="import" href="my-element.

html">● Templates: <template></template>

Polymer:● Data binding: <div>{{model}}</div>

Page 5: Polymer Code Lab in Dart - DevFest Kraków 2014
Page 6: Polymer Code Lab in Dart - DevFest Kraków 2014

Compatibility

● Chrome 36+● Polyfils

Page 7: Polymer Code Lab in Dart - DevFest Kraków 2014

Examples● https://www.polymer-project.org/● http://www.chromestatus.com/features● https://www.polymer-project.org/apps/topeka/● https://www.polymer-project.org/components/paper-calculator/demo.html● http://todomvc.com/architecture-examples/polymer/● http://googlewebcomponents.github.io/● http://customelements.io/● http://html5-demos.appspot.com/● http://builtwithpolymer.org/● http://devfest.gdgbeijing.org/● http://zenorocha.github.io/voice-elements/● http://www.gdgdc.com/● http://ebidel.github.io/material-playground/

Page 8: Polymer Code Lab in Dart - DevFest Kraków 2014

Why you should be excitedDeveloper productivity

● DOM + JS + CSS → no new APIs to learn!● say what you mean → readability

Re-usability

● don't reinvent the wheel● easy interop with other frameworks● CSS isolation

Good software engineering paradigms on web (OOP)

Page 9: Polymer Code Lab in Dart - DevFest Kraków 2014

Import Custom Element<!-- Polyfill Web Components support for older browsers -->

<script src="components/platform/platform.js"></script>

<!-- Import element -->

<link rel="import" href="google-map.html">

<!-- Use element -->

<google-map lat="37.790" long="-122.390"></google-map>

Page 10: Polymer Code Lab in Dart - DevFest Kraków 2014

Create Custom Element<polymer-element name="my-counter" attributes="counter">

<template>

<style> /*...*/ </style>

Value: <span>{{counter}}</span><br>

<button on-tap="{{increment}}">Increment</button>

</template>

<script src=”my-counter.dart” type=”application/dart”>

</script>

</polymer-element>

Page 11: Polymer Code Lab in Dart - DevFest Kraków 2014

Custom element dart codeimport 'package:polymer/polymer.dart' ;

import 'dart:html';

@CustomTag('my-counter')

class MyCounter extends PolymerElement {

@observable int counter = 0;

MyCounter.created() : super.created();

void increment(Event e, var detail, Node target) {

counter += 1;

}

}

Page 12: Polymer Code Lab in Dart - DevFest Kraków 2014

Custom attributes<my-volume volume="11"></my-volume>

@CustomTag('my-volume')

class MyVolume extends PolymerElement {

@published int volume = 0;

MyVolume.created() : super.created();

}

Page 13: Polymer Code Lab in Dart - DevFest Kraków 2014

Templates<template>

<template if="{{count <= 0}}">

<p>Click the button. It is fun!</p>

</template>

<template repeat="{{fruit in fruits}}">

<li>I like {{ fruit }}.</li>

</template>

</template>

Page 14: Polymer Code Lab in Dart - DevFest Kraków 2014

Extending DOM elements<button is="fancy-button">Click me</button>

import 'package:polymer/polymer.dart' ;

import 'dart:html' show ButtonElement;

@CustomTag('fancy-button')

class FancyButton extends ButtonElement with Polymer, Observable {

FancyButton.created() : super.created() {

polymerCreated();

}

}

Page 16: Polymer Code Lab in Dart - DevFest Kraków 2014

github.com/jskvara/dart-polymer-code-lab-krakow/