Slide 1

Slide 1 text

SvelteͰ࡞Δ WebComponents @yashi848484

Slide 2

Slide 2 text

ࣗݾ঺հ • Twitter: @yashi848484 • Like: WebϑϩϯτΤϯυ • Love: ΀Α΀Α • Recent troubles: ཱྀߦؼࠃศɺ୆෩Ͱܽߤ

Slide 3

Slide 3 text

ຊ೔఻͍͑ͨ͜ͱ • Svelteͱ͸Ͳ͏͍͏frameworkͳͷ͔ • ֤छframeworkʹґଘ͠ͳ͍ܗͰcomponentΛ࡞Δ ͱɺ༷ʑͳϓϩμΫτͰcomponentΛڞ༗Ͱ͖ͯศ རͦ͏

Slide 4

Slide 4 text

࡞ͬͨ΋ͷ • SvelteͰcustom elements(WebComponents)Λ࡞ͬͨ • ࡞ͬͨcustom elementsΛɺVue applicationͱReact applicationͷ྆ํͰ࢖ͬͯΈͨ

Slide 5

Slide 5 text

Svelteͱ͸ • https://svelte.dev/ • svélt: ͢ΒΓͱͨ͠ɺ͢ΜͳΓͱͨ͠ • .svelteίʔυΛɺjsʹม׵͢ΔίϯύΠϥ • (ࠓճ͸ɺ.svelte→custom elementsͱͯ͠ు͖ग़͢ ܗͰ࢖༻)

Slide 6

Slide 6 text

Svelteͱ͸ • ίʔυྔগͳ͘ॻ͚Δ͜ͱΛ໨తͱ͍ͯ͠Δ • Virtual DOMΛ࢖ΘͣɺDOMΛ௚઀ॻ͖׵͑ΔΞϓ ϩʔν • ࣮ߦ࣌ͷύϑΥʔϚϯε͕ྑ͍ɺͱݴΘΕ͍ͯΔ

Slide 7

Slide 7 text

Svelteͱ͸ • ύϑΥʔϚϯεʹؔͯ͠ɺVue΍Reactͱൺֱ͞ΕΔ ͜ͱ͕ଟ͍ • →jQuery౳ͱൺֱ͢Δ΄͏͕ϕλʔʁ

Slide 8

Slide 8 text

Hello {{ name }}

export default { data() { return { name: "world" }; } }; let name = "world";

Hello {name}

7VF 4WFMUF Svelte syntax

Slide 9

Slide 9 text

Hello world

h1 { color: red; } h1 { color: red; }

Hello world

Svelte syntax 7VF 4WFMUF

Slide 10

Slide 10 text

count: {{ count }}
button
export default { data() { return { count: 0 }; }, methods: { handleClick() { this.count += 1; } } }; let count = 0; function handleClick() { count += 1; }
count: {count}
button Svelte syntax 7VF 4WFMUF

Slide 11

Slide 11 text

Svelte syntax • data binding, style binding • if, eachͳͲͷϒϩοΫ • slot • ϥΠϑαΠΫϧϝιου • (؆қతͳ)store • transition, animation • (ҰԠ)contextAPI

Slide 12

Slide 12 text

WebComponents • ࠶ར༻ՄೳͳಠࣗͷΧελϜཁૉΛ࡞੒͠ɺ͜ΕΛ ΢ΣϒΞϓϦ಺Ͱར༻͢ΔͨΊͷٕज़ • Custom elements • Shadow DOM • HTML templates • HTML imports←ഇࢭ

Slide 13

Slide 13 text

Demo

Slide 14

Slide 14 text

export let title = "Svelte Card"; export let message = "This is card component created by svelte"; let selected = false; function handleOnClick() { selected = !selected; } /* লུ */
{title}
{message}
Svelte CustomElement

Slide 15

Slide 15 text

Svelte x {{ name }}

import "../public/svelte-elements"; WebComponents in Vue

Slide 16

Slide 16 text

return (

Svelte x {props.name}

{cards.map((card, i) => ( ))}
); WebComponents in React

Slide 17

Slide 17 text

ྑͦ͞͏ͳͱ͜Ζ • Svelte͸ɺsyntax͕Vueʹࣅ͍ͯΔ ɹˠVue.jsΛॻ͍͍ͯΔਓͰ͋Ε͹ɺΩϟονΞοϓ͸ָͦ͏ • ͔ͭɺΑΓίʔυྔগͳ͘ॻ͘͜ͱ͕Ͱ͖Δ • طʹVueͱReactͷϓϩμΫτ͕͋Γɺޙ͔ΒσβΠϯͷ౷Ұ ԽΛਤΓ͍ͨ৔߹ͳͲʹWebComponents͸ศརͦ͏

Slide 18

Slide 18 text

՝୊ • SvelteʹΑΔcustom elementsు͖ग़͠͸ɺSvelteͷ͓·͚ػೳ ɹˠΞϓϦέʔγϣϯ࡞੒༻్ͰਅՁΛൃشͰ͖Δ⭕ • Svelte͸TypeScriptະαϙʔτ ɹˠࠓޙαϙʔτ͞ΕΔ༧ఆ • WebComponentsॳΊͯ࢖ͬͨͷͰɺࠓޙ஌ࣝΛਂΊ͍͖͍ͯͨ

Slide 19

Slide 19 text

Source https://github.com/yashi8484/svelte-custom-elements

Slide 20

Slide 20 text

Thank you!