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
Inside hyperapp
Search
Yusaku Omasa
February 26, 2018
Technology
240
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Inside hyperapp
Yusaku Omasa
February 26, 2018
More Decks by Yusaku Omasa
See All by Yusaku Omasa
Data Transformation in Digdag
taise
0
2.2k
Rails on CircleCI Tuning
taise
0
140
データ分析基盤Night #2
taise
2
5.6k
Other Decks in Technology
See All in Technology
AI駆動開発における開発環境のセキュリティの考え方
yamahiro
2
420
ソフトウェア ファクトリー - 再現性のあるソフトウェアの工場づくり / Software factory
iktakahiro
7
5.3k
macOS Golden Gate 時代のMac管理
tategami
0
130
Turning Repos into the Product Second Brain with an LLM Wiki
linedevth
0
140
[JAWS-UG彩の国埼玉#12]そろそろ準備する?re:Invent2026をやさしく解説 / reinvent2026-sainokuni
sh_fk2
1
400
小規模OSSモデルは サイバーセキュリティ業務に どこまで使えるか
bbrbbq
0
200
VLA-JEPA: Enhancing Vision-Language-Action Models with Latent World Models
takmin
0
160
生成AI時代、PMは事業責任者に進化するともっと面白い〜PMだからこそ事業構造を動かせる時代に〜
kakehashi
PRO
0
450
ストレスなくAIと付き合いたい!こんなときどうしてる?
namiki64
4
670
野蛮なアジャイル [サイボウズ発!]組織の常識を覆した反骨のスクラム実践記 / Barbaric Agile - Enterprise Agile Study Group
ama_ch
0
130
[EMNLP26] RIGEL: Self-Distilled Score Adaptation for Image and Video Captioning Evaluation
keio_smilab
PRO
0
120
「私が一番顧客に詳しい」を捨てる~ 全員が一次情報に精通する開発チームをつくり、PMが次のボトルネックへ染み出すまで
kaminashi
3
1.5k
Featured
See All Featured
Embracing the Ebb and Flow
colly
88
5.2k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
Test your architecture with Archunit
thirion
2
2.4k
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
460
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
2
540
Mobile First: as difficult as doing things right
swwweet
225
10k
VelocityConf: Rendering Performance Case Studies
addyosmani
331
25k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
Fireside Chat
paigeccino
43
4.1k
Building the Perfect Custom Keyboard
takai
2
910
Abbi's Birthday
coloredviolet
4
10k
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
260
Transcript
Inside hyperapp How to implement virtual dom 0x64 Stories Yusaku
Omasa
Hello! Yusaku Omasa. Twitter: @_eurk Web Engineer & Data Engineer
None
Hyperappとは 2017年のAdvent Calendarで Qiitaのエンジニアが開発し 実際にプロダクトでも採用 されたことで話題になった JavaScriptのFrameworkの ことである。 ref: 2018
年は Hyperapp の年だ
Hyperappとは (抄訳) Hyperapp is a JavaScript library for building web
applications. • Minimal ◦ 小さな実装で、多くのことに対応する試み。 あなたが理解すべきコンセプトも最小にしつつ、他のFrameworkができることを維持する。 • Functional ◦ The Elm Architectureにインスパイアされて設計している。 関数型パラダイムを使い、スケーラブルにブラウザベースのアプリケーションを作れる。 新しい言語を学ぶ必要はない。 • Batteries-included ◦ そのままの状態で、Hyperappはstate管理と仮想DOMエンジンなどの依存するものを全て含んでいる。 ref: https://github.com/hyperapp/hyperapp/blob/master/README.md
Hyperappとは ref: https://codepen.io/hyperapp/pen/zNxZLP?editors=0010
Hyperappとは ref: 1 KB にこだわった理由、1 KB であることの利点
Hyperappとは ref: 1 KB にこだわった理由、1 KB であることの利点
1KBのコードを読むのに 6時間かかりました (JSエンジニアではないとはいえ)
hyperapp design
• h() ◦ HTMLのタグをモデル化したもの ◦ JSXから変換可能になっている • app() ◦ Framework本体
▪ State管理 ▪ actionとstateの紐付け ▪ Lifecycle ▪ Virtual dom更新 ▪ レンダリングロック Reactにほぼ近く、router、SSR用のrenderなどは、関連packageがある Frontend MVC、validationみたいなものはない Hyperapp design
Hyperapp design import { h, app } from "hyperapp" const
state = { count: 0 } const actions = { down: value => state => ({ count: state.count - value }), up: value => state => ({ count: state.count + value }) } const view = (state, actions) => ( <div> <h1>{state.count}</h1> <button onclick={() => actions.down(1)}>-</button> <button onclick={() => actions.up(1)}>+</button> </div> ) app(state, actions, view, document.body)
Hyperapp design • Virtual DOM ◦ わりかし普通の木構造。 JavaScriptのObjectそのもの。 ▪ Nodeを基本単位として、
Nodeが再帰的に子Nodeを持つ ▪ 要素 • nodeName • attributes • children ref: https://github.com/hyperapp/hyperapp/blob/master/README .md#virtual-dom
Hyperapp design Virtual DOMの設計について • JSX互換性を維持するために babel pluginのtransform-react-jsx を使えるようにしており、この pluginが
Virtual DOMの設計を規定しているように見える。 (React.jsも同じ構造) • transform-react-jsx は、そのまま使うとReact.createElement() のかたちでNode Treeを 出力するが、JSXファイルで import { h } from "hyperapp"をすると h()に切り替えて出力する。
Process Flow Hyperapp design scheduleRender render action renderLock wait 1
msec patch unlock lifecycleStack push pop ① ② ③ ④ createElement
• action ◦ app()でProcess Flowに組み込まれる ◦ function wireStateToActions(path, state, actions)
{} でactionの関数を再定義して app直下にあるwiredActionsに登録される ▪ actionによってstateが変更 & actionがPromiseではないときだけ、 globalState を更新して、 scheduleRender() を呼び出す ◦ actionのトリガはonClickなどでView側に埋め込む Hyperapp design const actions = { down: value => state => ({ count: state.count - value }), up: value => state => ({ count: state.count + value }) } app(state, actions, view, document.body) <button onclick={() => actions.down(1)}>-</button>
Action関数の再定義って どうやって実装するの? こうやっている ===> これだけだと読むのが辛いので、 コードにメモを付けたブランチを作り ました https://github.com/taise/hyperapp/tree/memo Hyperapp design
Hyperapp design • StateとActionの紐づけ ◦ key: up ◦ action: value
=> state => ({ count: state.count + value }) • 関数の再定義 ◦ L136: actions[key] = function(data){} ◦ L150: action() はコメントアウトのところの ような呼び出し方をしている ◦ { count: state.count + value } で渡して いるので、stateと同じ形で返る ◦ state の値が変わっていて、 data が Promise ではない時に、globalState を更新しつつ、 scheduleRender() が呼び出される ◦ dataを返して終了
• hyperappは、たしかに読み切れるサイズのライブラリ ◦ React.jsとかを読むのと比べると遥かに簡単 ◦ JSエンジニアなら1~2時間くらいで読めるかもしれないけど サーバーサイド エンジニアは6時間かかったよ • FWのような抽象化されたライブラリの設計を読み解きながら
コードリーディングするのは楽しく、学びが多い ◦ 処理フローを図式化しながらやると、頭も整理されてよい 他にもrenderやpatchなど、なかなか読み応えがあるので、 レベルアップしたいJSエンジニアは読んでみると良いかもしれない https://github.com/taise/hyperapp/tree/memo まとめ