Slide 1

Slide 1 text

Polymer Google Developer Group Hackathon.

Slide 2

Slide 2 text

Creating Reusable Elements +AddyOsmani @addyosmani

Slide 3

Slide 3 text

Apps should be composed of reusable, responsive & testable elements.

Slide 4

Slide 4 text

Examples

Slide 5

Slide 5 text

Bad Reusable

Slide 6

Slide 6 text

Bad Reusable

Slide 7

Slide 7 text

Not

Slide 8

Slide 8 text

Not

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

Today you might write an

Slide 11

Slide 11 text

Element Docs Tests

Slide 12

Slide 12 text

Element Create a component we’ve all written before.

Slide 13

Slide 13 text

Tabs http://drbl.in/bAsu http://drbl.in/esYL

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

PILE ON THE JAVASCRIPT

Slide 19

Slide 19 text

https://www.flickr.com/photos/ darkismus/4179361946

Slide 20

Slide 20 text

https://www.flickr.com/photos/ goodspeed/2669719176

Slide 21

Slide 21 text

http://goo.gl/lKk7iT

Slide 22

Slide 22 text

Tabs using web components

Slide 23

Slide 23 text

! Tab 1 Tab 2 Tab 3 HTML

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

No content

Slide 26

Slide 26 text

! Tab 1 Tab 2 Tab 3 HTML

Slide 27

Slide 27 text

Building a tabs element

Slide 28

Slide 28 text

No content

Slide 29

Slide 29 text

No content

Slide 30

Slide 30 text

No content

Slide 31

Slide 31 text

Start with github.com/PolymerLabs/seed-element

Slide 32

Slide 32 text

No content

Slide 33

Slide 33 text

Download Boilerplate

Slide 34

Slide 34 text

/development /seed-element /tests .bowerrc bower.json demo.html index.html README.md seed-element.css seed-element.html Unzip it locally Workspace Element

Slide 35

Slide 35 text

/development /seed-element /tests .bowerrc bower.json demo.html index.html README.md seed-element.css seed-element.html Boilerplate files Rename for my-tabs

Slide 36

Slide 36 text

/development /my-tabs /tests .bowerrc bower.json demo.html index.html README.md my-tabs.css my-tabs.html Renamed files

Slide 37

Slide 37 text

bower.io

Slide 38

Slide 38 text

$ npm install -g bower Terminal

Slide 39

Slide 39 text

$ npm install -g bower ! npm http GET https://registry.npmjs.org/bower npm http 200 https://registry.npmjs.org/bower npm http GET https://registry.npmjs.org/bower/-/bower-1.3.3.tgz npm http 200 https://registry.npmjs.org/bower/-/bower-1.3.3.tgz npm http GET https://registry.npmjs.org/bower-endpoint-parser npm http GET https://registry.npmjs.org/bower-json npm http GET https://registry.npmjs.org/bower-config npm http GET https://registry.npmjs.org/bower-logger npm http GET https://registry.npmjs.org/bower-registry-client npm http GET https://registry.npmjs.org/insight … Terminal

Slide 40

Slide 40 text

~/development/my-tabs $ bower install Terminal

Slide 41

Slide 41 text

~/development/ $ ls ! core-action-icons core-component-page my-tabs platform polymer chai mocha Terminal

Slide 42

Slide 42 text

~/development/ $ ls ! core-action-icons core-component-page my-tabs platform polymer chai mocha Terminal Avoids nested dependency trees my-tabs / bower_components my-toolbar / bower_components my-button / bower_components

Slide 43

Slide 43 text

! ! ! ! Polymer(‘seed-element’, {…}); my-tabs.html

Slide 44

Slide 44 text

! ! ! ! my-tabs.html noscript if not using JS

Slide 45

Slide 45 text

RE-USING ELEMENTS

Slide 46

Slide 46 text

polymer-project.org/docs/elements/

Slide 47

Slide 47 text

http://polymer.github.io/core-docs/ #core-selector

Slide 48

Slide 48 text

http://polymer.github.io/core-docs/ #core-selector

Slide 49

Slide 49 text

http://polymer.github.io/core-docs/ #core-selector

Slide 50

Slide 50 text

! $ bower install Polymer/core-selector —save Terminal

Slide 51

Slide 51 text

! $ bower install Polymer/core-selector —save ! bower cached git://github.com/Polymer/core-selector.git#0.3.0 bower validate 0.3.0 against git://github.com/Polymer/core-selector.git#* bower not-cached git://github.com/Polymer/core-selection.git#>=0.3.0 <1.0.0 bower resolve git://github.com/Polymer/core-selection.git#>=0.3.0 <1.0.0 bower not-cached git://github.com/Polymer/polymer.git#>=0.3.0 <1.0.0 bower resolve git://github.com/Polymer/polymer.git#>=0.3.0 <1.0.0 Terminal

Slide 52

Slide 52 text

! ! !

Slide 53

Slide 53 text

! ! ! ! ! my-tabs.html

Slide 54

Slide 54 text

! ! ! ! ! my-tabs.html

Slide 55

Slide 55 text

:host { font-family: ‘Roboto’, ‘Arial’, sans-serif; } ! polyfill-next-selector { content: ':host > .core-selected'; } ::content > .core-selected { background: #5599FF; color: white; } ! polyfill-next-selector { content: ':host > *'; } ::content > * { min-width: 60px; height: 60px; line-height: 60px; text-align: center; padding: 0 8px; font-size: 14px; color: #999; } my-tabs.css

Slide 56

Slide 56 text

! Tab 1 Tab 2 Tab 3 Ideal usage

Slide 57

Slide 57 text

! Tab 1 Tab 2 Tab 3 Ideal usage

Slide 58

Slide 58 text

! ! !
! my-tabs.html

Slide 59

Slide 59 text

my-tabs Demo ! ! ! demo.html

Slide 60

Slide 60 text

... ! One Two Three ! demo.html

Slide 61

Slide 61 text

... ! One Two Three ! demo.html selected=“0” selects the first tab

Slide 62

Slide 62 text

! $ python -m SimpleHTTPServer 8000 Terminal

Slide 63

Slide 63 text

No content

Slide 64

Slide 64 text

No content

Slide 65

Slide 65 text

Deployment

Slide 66

Slide 66 text

ELEMENTS CAN BE SHARED

Slide 67

Slide 67 text

No content

Slide 68

Slide 68 text

No content

Slide 69

Slide 69 text

Push to master!

Slide 70

Slide 70 text

Push docs, demos, landing page to gh-pages! Next

Slide 71

Slide 71 text

~/development/my-tabs $ cd .. Terminal

Slide 72

Slide 72 text

$ mkdir temp && cd temp Terminal

Slide 73

Slide 73 text

$ git clone git://github.com/Polymer/tools.git ! Cloning into 'tools'... remote: Reusing existing pack: 1201, done. remote: Total 1201 (delta 0), reused 0 (delta 0) Receiving objects: 100% (1201/1201), 834.45 KiB | 277.00 KiB/s, done. Resolving deltas: 100% (476/476), done. Checking connectivity... done. ! ! Terminal

Slide 74

Slide 74 text

$ ./tools/bin/gp.sh my-tabs Terminal

Slide 75

Slide 75 text

http://bit.ly/NZmXRP

Slide 76

Slide 76 text

http://addyosmani.github.io/my-tabs

Slide 77

Slide 77 text

No content

Slide 78

Slide 78 text

No content

Slide 79

Slide 79 text

No content

Slide 80

Slide 80 text

No content

Slide 81

Slide 81 text

Docs Automatically scraped and generated from source.

Slide 82

Slide 82 text

No content

Slide 83

Slide 83 text

No content

Slide 84

Slide 84 text

No content

Slide 85

Slide 85 text

No content

Slide 86

Slide 86 text

https://www.flickr.com/photos/ bensutherland/2274353620

Slide 87

Slide 87 text

Tests Unit testing your elements

Slide 88

Slide 88 text

No content

Slide 89

Slide 89 text

! var myEl = document.querySelector('seed-element'); assert.equal(myEl.author, 'Dimitri Glazkov'); Test properties

Slide 90

Slide 90 text

! var hello = myEl.sayHello(); assert.equal(hello, 'seed-element says, Hello World!'); ! var greetings = myEl.sayHello('greetings Earthlings'); assert.equal(greetings, 'seed-element says, greetings Earthlings'); Test methods

Slide 91

Slide 91 text

! myEl.addEventListener('seed-element-lasers-success', function(event) { ! assert.equal(event.detail.sound, 'Pew pew pew!'); done(); }); ! myEl.fireLasers(); Test events

Slide 92

Slide 92 text

No content

Slide 93

Slide 93 text

Elements ! Docs ! Tests !

Slide 94

Slide 94 text

No content

Slide 95

Slide 95 text

GO COMPONENTIZE THE WEB TODAY

Slide 96

Slide 96 text

Thank you! #componentizetheweb +AddyOsmani @addyosmani

Slide 97

Slide 97 text

github.com/PolymerLabs/seed-element