Top Banner
@LostInBrittany #wcremoteconf WEB COMPONENTS REMOTE CONF 2017 But there is no web component for that! Horacio Gonzalez @LostInBrittany
40

But there is no web component for that - Web Components Remote Conference - 2017-02-16

Jan 22, 2018

Download

Technology

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: But there is no web component for that - Web Components Remote Conference - 2017-02-16

@LostInBrittany#wcremoteconf

WEB COMPONENTS REMOTE CONF

2017

But there is no web component for that!

Horacio Gonzalez @LostInBrittany

Page 2: But there is no web component for that - Web Components Remote Conference - 2017-02-16

@LostInBrittany#wcremoteconf

Who am I?Horacio Gonzalez@LostInBrittany

Cityzen Datahttp://cityzendata.com

Spaniard lost in Brittany, developer, dreamer and all-around geek

Page 3: But there is no web component for that - Web Components Remote Conference - 2017-02-16

@LostInBrittany#wcremoteconf

IntroductionContext is everything

Page 4: But there is no web component for that - Web Components Remote Conference - 2017-02-16

@LostInBrittany#wcremoteconf

There is no webcomponent for that!

So there is no web component for your nifty feature…

But there is a JS library

What can I do?

Page 5: But there is no web component for that - Web Components Remote Conference - 2017-02-16

@LostInBrittany#wcremoteconf

It isn't a theoretical problem

Maybe you won't never have this problem

And that's OK!

But I had the problem, so I had to find an answer

Talk by Raphaël tomorrow

Page 6: But there is no web component for that - Web Components Remote Conference - 2017-02-16

@LostInBrittany#wcremoteconf

I was kinda an AngularJS fanboy

Page 7: But there is no web component for that - Web Components Remote Conference - 2017-02-16

@LostInBrittany#wcremoteconf

Until I hit a wall

Page 8: But there is no web component for that - Web Components Remote Conference - 2017-02-16

@LostInBrittany#wcremoteconf

Enter Web Components & Polymer

WebComponents, a modular approach to webapps

Page 9: But there is no web component for that - Web Components Remote Conference - 2017-02-16

@LostInBrittany#wcremoteconf

And it worked!

We put our first Polymer app in production on 2014 with Polymer 0.4Full story: http://blog.cityzendata.com/2015/02/07/behind-CES-colors/

Page 10: But there is no web component for that - Web Components Remote Conference - 2017-02-16

@LostInBrittany#wcremoteconf

It was there I met the problem...

I used D3.js, NVD3 and canvas for my dataviz

But there was nothing like that in Polymer

What could I do?

Page 11: But there is no web component for that - Web Components Remote Conference - 2017-02-16

@LostInBrittany#wcremoteconf

For each problem there is a solution

I saw several solutions:● Wait for the web component● Dirty integrating the library● Componentalize it

Guess which one I chose...

Page 12: But there is no web component for that - Web Components Remote Conference - 2017-02-16

@LostInBrittany#wcremoteconf

It was only the first time...

Page 13: But there is no web component for that - Web Components Remote Conference - 2017-02-16

@LostInBrittany#wcremoteconf

How do I componentalize them?

Page 14: But there is no web component for that - Web Components Remote Conference - 2017-02-16

@LostInBrittany#wcremoteconf

Componentalizing a libraryLet's begin with a simple example

Page 15: But there is no web component for that - Web Components Remote Conference - 2017-02-16

@LostInBrittany#wcremoteconf

granite-qr-generator

Page 16: But there is no web component for that - Web Components Remote Conference - 2017-02-16

@LostInBrittany#wcremoteconf

What QR Code library to use?

I choose QR.jshttps://github.com/lifthrasiir/qr.js/

● Small ○ 26 kb uncompressed and commented

● Quick!● Well coded

○ Structured, lots of comments, clean code

● No dirty DOM manipulation

Page 17: But there is no web component for that - Web Components Remote Conference - 2017-02-16

@LostInBrittany#wcremoteconf

Steps

1. Creating an empty element

2. Add the library as a dependency

3. Load the library in the element file

4. Build a web component encapsulating it

5. Profit?

Page 18: But there is no web component for that - Web Components Remote Conference - 2017-02-16

@LostInBrittany#wcremoteconf

"Build a web component encapsulating it"

Easier said than done?

1. Define the inputs (attributes)2. Define the outputs (events)3. Define the UI (template)4. Wire the attributes and events to the

library5. Use the lifecycle methods to initialize

Page 19: But there is no web component for that - Web Components Remote Conference - 2017-02-16

@LostInBrittany#wcremoteconf

Define the inputs (attributes)

Page 20: But there is no web component for that - Web Components Remote Conference - 2017-02-16

@LostInBrittany#wcremoteconf

Define the outputs (events)

Page 21: But there is no web component for that - Web Components Remote Conference - 2017-02-16

@LostInBrittany#wcremoteconf

Define the UI (template)

Page 22: But there is no web component for that - Web Components Remote Conference - 2017-02-16

@LostInBrittany#wcremoteconf

Wire the attributes and events to the library

Page 23: But there is no web component for that - Web Components Remote Conference - 2017-02-16

@LostInBrittany#wcremoteconf

Wire the attributes and events to the library

Page 24: But there is no web component for that - Web Components Remote Conference - 2017-02-16

@LostInBrittany#wcremoteconf

Wire the attributes and events to the library

Page 25: But there is no web component for that - Web Components Remote Conference - 2017-02-16

@LostInBrittany#wcremoteconf

granite-qr-generator

Page 26: But there is no web component for that - Web Components Remote Conference - 2017-02-16

@LostInBrittany#wcremoteconf

granite-qrcode-scanner

Page 27: But there is no web component for that - Web Components Remote Conference - 2017-02-16

@LostInBrittany#wcremoteconf

What QR Code scan library to use?

I choose jsqrcodehttps://github.com/LazarSoft/jsqrcode

● Small for a full QR Code scanner○ 110 kb uncompressed and commented

● Quick and efficient● Well coded

○ Structured, lots of comments, clean code

● But with some dirty DOM manipulation

Page 28: But there is no web component for that - Web Components Remote Conference - 2017-02-16

@LostInBrittany#wcremoteconf

Steps

1. Creating an empty element

2. Add the library as a dependency

3. Load the library in the element file

4. Build a web component encapsulating it

5. Profit?

Page 29: But there is no web component for that - Web Components Remote Conference - 2017-02-16

@LostInBrittany#wcremoteconf

"Build a web component encapsulating it"

Easier said than done?

1. Define the inputs (attributes)2. Define the outputs (events)3. Define the UI (template)4. Wire the attributes and events to the

library5. Use the lifecycle methods to initialize

Page 30: But there is no web component for that - Web Components Remote Conference - 2017-02-16

@LostInBrittany#wcremoteconf

Define the inputs and outputs

Page 31: But there is no web component for that - Web Components Remote Conference - 2017-02-16

@LostInBrittany#wcremoteconf

Define the UI (template)

Page 32: But there is no web component for that - Web Components Remote Conference - 2017-02-16

@LostInBrittany#wcremoteconf

Initializing in the lifecycle methods

Page 33: But there is no web component for that - Web Components Remote Conference - 2017-02-16

@LostInBrittany#wcremoteconf

Initializing in the lifecycle methods

Page 34: But there is no web component for that - Web Components Remote Conference - 2017-02-16

@LostInBrittany#wcremoteconf

But what about the wiring?

Almost no wiring needed

● Either done in the template

● Or in the initialization

Page 35: But there is no web component for that - Web Components Remote Conference - 2017-02-16

@LostInBrittany#wcremoteconf

And then, does it work?

Weeeeell, not really…

And it doesn't give a clear error

What does it happen here ?

Page 36: But there is no web component for that - Web Components Remote Conference - 2017-02-16

@LostInBrittany#wcremoteconf

Digging in the problem

Going deep inside the libraryAdding logs and breakpointsAnd I found the guilty line:

Page 37: But there is no web component for that - Web Components Remote Conference - 2017-02-16

@LostInBrittany#wcremoteconf

Patching the library

Doing it the open source way...

Page 38: But there is no web component for that - Web Components Remote Conference - 2017-02-16

@LostInBrittany#wcremoteconf

granite-qrcode-scanner

Page 39: But there is no web component for that - Web Components Remote Conference - 2017-02-16

@LostInBrittany#wcremoteconf

Other examples: ace-widget

Page 40: But there is no web component for that - Web Components Remote Conference - 2017-02-16

@LostInBrittany#wcremoteconf

Thanks!I hope you liked this talk!

Don't hesitate to send me your questions by email, twitter, hangout, carrier pigeon...