Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Vanilla JS challenge
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
tomoaki kanayama
February 11, 2024
Programming
190
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Vanilla JS challenge
tomoaki kanayama
February 11, 2024
More Decks by tomoaki kanayama
See All by tomoaki kanayama
Gemini API で デロリアン
aknow2
0
160
Other Decks in Programming
See All in Programming
Verilogで学ぶCPU自作入門
uyuki234
8
4k
Everything will be SERVERLESS — 信じて運用した10年の経験値 / Everything Will be Serverless — Lessons Learned from 10 Years of Operational Experience
seike460
PRO
1
790
コードレビューのボトルネックを"する側"と"される側"の両面から解消する
yub0n
2
1.5k
Java 27新機能 / Java 27 new features
kishida
2
200
そのリトライ、死んだコネクションを使い回していませんか ── GoのHTTPクライアントとHTTP/2を実プロダクト障害から学び直す
myus4a
0
400
CodeRabbitの効果検証と過ごしてみた3ヶ月
armondando
0
180
contenteditable と日本語入力に向き合う
colorful12
0
170
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
560
モバイル交通系ICへのチャージ実例から考える、クロスプラットフォーム開発におけるiOS実機テスト設計とCI運用
yusuga
1
580
【加筆修正版】Laravel のアプリケーションをどこにデプロイするか #phpcon_ehime
akase244
0
150
AI時代のコードレビューは人に向けるな、仕組みに向けろ
texmeijin
5
3.5k
KiroのSpecで「五目並べ」を作ってみる
satoshi256kbyte
1
360
Featured
See All Featured
Fashionably flexible responsive web design (full day workshop)
malarkey
409
67k
Automating Front-end Workflow
addyosmani
1369
210k
Abbi's Birthday
coloredviolet
4
10k
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
440
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
450
Embracing the Ebb and Flow
colly
88
5.2k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
320
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.4k
SEO Brein meetup: CTRL+C is not how to scale international SEO
lindahogenes
2
2.9k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
203
76k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.6k
Transcript
Vanilla JS challenge 金山智昭
だれ 金山智昭 (Kanayama Tomoaki) 三重県津市在住のプログラマーです Frontend(React, Vue, webgl) Apps (Electron,
ReactNative) Cloud (AWS, Firebase, Supabase) Backend (django, RoR) GeoVisualization Agile
去年末のある日 https://www.youtube.com/shorts/91WgzdDF3yk
アプリにしたら楽しそう
作った https://6-ro.com
今回開発する上での縛り 1. ブラウザで動作するWebアプリ プラットフォームとか考えるとネイティブ面倒 HTMLとjsのみで動作する 2. Vanilla jsで行く http://vanilla-js.com/ 要は全部自分で書く
モチベーション ReactとかVue、Three, p5とか.jsはもうお腹いっぱい 最近はWeb標準のAPIでも色々出来るようになってきている FWを使わずに、Web標準でどこまで快適に行けるか試してみよう
開始10分後
ただし、色々面倒なので以下は使う Vite 開発体験向上(HMR, Bundler, unittest) Typescript WebGL回りはコードがゴチャるのでTypescriptがあった方が安心 というかChatGPTが吐いたコードが、、、
Vanilla.jsで試したい事 コンポーネント指向の開発 AngularやVue,Reactでの流行り始めたやつ UI(ボタン、フォーム)とかパーツかして使い回せる様にして開発する 従来はCSSで実現してたが、DOMや振る舞いまで使い回せるところが違う Reactive 値が変わったら勝手にUIが更新されるよ!ってやつ(後述) CSS SCSSいらん CSS
in JSもいらん WebGL WebGPU WebGL2 WebGL
コンポーネント指向の開発 React // index.jsx function HelloWorld(props) { return <span className="title">Hello!
{props.name}<span> } function Root() { return <div> <HelloWorld name="world"> <HelloWorld name="vanilla js"> </div> }
コンポーネント指向の開発 Web component <!-- DOMを独自に定義 --> <hello-world name="world"> <hello-world name="Vanilla
JS"> class HelloWorld extends HTMLElement { connectedCallback() { const shadow = this.attachShadow({ mode: 'closed' }); // このコンポーネント専用のCSSが書ける shadow.innerHTML = /* html */ ` <style> span { text-align: center; } </style> <span>Hello ${ this.name }!</span>`; } } defineComponent('hello-world', HelloWorld)
Reactive 状態が変わったら勝手にUIが更新される Excelの表を想像
Reactive Web component <Counter id="counter" count="0"></counter> class Counter extends HTMLElement
{ // 属性の値が変わったら更新される attributechangedcallback() { const shadow = this.shadowRoot; const count = this.getAttribute('count') shadow.innerHTML = /* html */ ` <span>Count: ${ count }!</span>`; } } const counter = document.getElementById('counter') counter.setAttribute("count", "6")
Reactive 状態管理 特に目新しい事が無くて、面白味がないので割愛 いわゆるObserberパターンで実装
CSS コンポーネントに閉じられるので、名前被りの心配は要らない(BEMとか要らない) グローバルなCSSが出来ないのが逆に面倒。色とかは、共通CSSを準備して全ての コンポーネントで読み込んでいる。かなり冗長 CSSのネストもサポートされはじめたしSCSSは不要では?
WebGL WebGPUを使ってみたかったが、Safariとかが未対応だったのでWebGL2を採用 正直、簡単に書きたいならライブラリ使った方が良い Shaderで細かく調整したいなら、生で書いた方が楽そう 特に今回は全体を回転させたり、特殊な事を色々したかったので、ライブラリ使 わずにやったのは正解だった気がする # vertex ... void
main() { ... mat2 rotation = mat2(c, -s, s, c); gl_Position = vec4(rotation * a_position, 0.0, 1.0); } # fragment void main(){ gl_Frag_color = v_color; }
まとめ FWのバージョンアップに悩まされないし、趣味で書くにはフレームワーク要らな いんじゃね?とはなる まともに仕事で開発しようと思ったら、まだまだ辛い チームで開発するにはオレオレフレームワークにせざるを得ないので、規律を決 めるのが面倒そう
None