Share
Embed
Custom Elements in UIT
2019/8/21に開催されたUIT Meetup Fukuoka vol.1での登壇資料です
LINE Developers
August 21, 2019
Transcript
33 slides
-
Custom Elements in UIT ⿈慈霖 Huang, Tzu-Lin UIT Team, LINE
Fukuoka @UIT meetup Fukuoka vol.1 「現場におけるフロントエンド」 2019/08/21 1 / 33 -
⾃⼰紹介 About me From Taiwan 台湾 Join LINE Fukuoka in
2016 Front-end developer for 8 years 5 / 33 -
⾃⼰紹介 About me From Taiwan 台湾 Join LINE Fukuoka in
2016 Front-end developer for 8 years Sticker shop ( スタンプショップ) Theme shop ( 着せかえショップ) Custom sticker ( カスタムスタンプ) CMS 6 / 33 -
What is Custom Elements? A component library native to the
browser No additional bytes of a framework for the user to download, parse and compile. WHATWG Spec https://html.spec.whatwg.org/multipage/custom- elements.html#custom-elements 7 / 33 -
Why do we choose Custom Elements Let's talk about Custom
Sticker ( カスタムスタンプ) a little bit. 11 / 33 -
The Editor It was first made for in-house sticker designer
exclusively. (Name Sticker CMS) 13 / 33 **** **** -
The Editor It was first made for in-house sticker designer
exclusively. (Name Sticker CMS) LINE Creators Market will deliver the same feature soon. 14 / 33 **** **** -
The Editor It was first made for in-house sticker designer
exclusively. (Name Sticker CMS) LINE Creators Market will deliver the same feature soon. Don't reinvent the wheel 15 / 33 **** **** -
Other reasons We don't have to support mobile browsers. The
common web components of the editor must be compatible with Vue. Name Sticker CMS No Framework LINE Creators Market 16 / 33 -
How does it look like in code? In package.json "dependencies":
{ "@linecorp/name-sticker-editor": "1.1.1" } Then in HTML Just like a regular HTML tag <script src="/name-sticker-editor/dist/name-sticker-editor.js"></scri <name-sticker-editor src="url/to/sticker/image" safe-area-color="#0003"> </name-sticker-editor> 18 / 33 -
Access via JS const nameStickerEditor = document.querySelector("name-sticker-editor nameStickerEditor.src = "url/to/sticker/image";
nameStickerEditor.resetPath(); nameStickerEditor.addEventListener("change", evt => {}); 19 / 33 -
What have we learned? Need a convenient tool in development
phase Home-made Storybook Packaging and distribution of custom elements Scenarios that suitable and not suitable for Custom Elements 20 / 33 -
Storybook https://storybook.js.org/ A better tool for developers and users of
the custom elements to play with 22 / 33 -
Packaging Bundled with webpack Users need to put it in
<script> tag before using it Not flexible enough if users want to bundle themselves and use it directly in JS Lesson Learned Multiple builds: umd and esm <script src="/name-sticker-editor/dist/name-sticker-editor.js"></scri import { NameStickerEditor } from "node_modules/name-sticker-editor/i 23 / 33 -
Distribution Host on Github Enterprise Some CI fail because they
don't support git+ssh "dependencies": { "loading-indicator": "git+ssh://git.repo.host:org/loading-indicat } 25 / 33 -
Distribution Host on Github Enterprise Some CI fail because they
don't support git+ssh Some other CI fail because they don't have permission to access to Github enterprise in https. "dependencies": { "loading-indicator": "git+ssh://git.repo.host:org/loading-indicat } "dependencies": { "loading-indicator": "https://git.repo.host/org/loading-indicator } 26 / 33 -
Lesson Learned in Distribution Distribute them on npm (or private
npm) the first day. Discuss with your users earlier 27 / 33 -
Scenarios not suitable for Custom Elements Custom Elements are not
silver bullets. 28 / 33 -
Scenarios not suitable for Custom Elements Custom Elements are not
like React Components or Vue Components. We still have to do state management ourselves. Encapsulation custom elements in layers of layers just brought us more problems. 29 / 33 -
The encapsulation problem we met In the source code of
<range-and-color>, we have to explicitly propagate the change event. Because change events do not propagate out of shadow DOM. https://developers.google.com/web/fundamentals/web- components/shadowdom#events twoToneSlider.addEventListener("change", evt => { this.dispatchEvent(new CustomEvent(evt.type, { detail: evt.detail } }); 31 / 33 -
Suitable Scenarios of Custom Elements Enhance existing HTML elements Something
which is difficult to implement with only HTML and CSS 32 / 33