Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Mithrilの紹介/Introduce of Mithril
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
MURAKAMI Masahiko
March 02, 2017
Programming
330
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Mithrilの紹介/Introduce of Mithril
MURAKAMI Masahiko
March 02, 2017
More Decks by MURAKAMI Masahiko
See All by MURAKAMI Masahiko
AWS Amplifyをもっと便利に使うための取り組み/amplify-tools-and-contributions
fossamagna
1
150
Amazon Verified Permissions実践入門 〜Cedar活用とAppSync導入事例/Practical Introduction to Amazon Verified Permissions
fossamagna
2
370
Amplify Gen2から知るAWS CDK Toolkit Libraryの使い方/How to use the AWS CDK Toolkit Library as known from Amplify Gen2
fossamagna
1
900
AWS Amplify Gen2向けのVSCode拡張を作って公開してみた話/lts-techday-2024
fossamagna
0
49
CDKアプリとしてのAmplify Gen2 - @aws-amplify/backendのアーキテクチャにみるCDKベストプラクティス -
fossamagna
3
3.7k
Amplify Gen2の 新機能と実践的な使用例 AWS Amplify Gen 2 Festival in Japan/New features and practical use cases in Amplify Gen2
fossamagna
0
850
Amplify Gen2を 拡張してみよう JAWS-UG北陸新幹線 ( 福井開催 ) 2024-04-06/Let's extend Amplify Gen2
fossamagna
0
1k
みんな本当に AWS Amplify を知っている?/do-you-really-know-aws-amplify
fossamagna
0
200
Amplify OSSにコントリビュートしてAmplify Badgeを手に入れよう!/contribute-to-amplify-oss-and-get-an-amplify-badge
fossamagna
0
630
Other Decks in Programming
See All in Programming
Javaの型とAI時代に型が大事な理由 / java types and type in AI era
kishida
2
130
Lemonade + Foundry Toolkit でお手軽アプリ開発
seosoft
1
330
ユニットテストの先へ:テスト技法で要求・仕様を整理するJava開発実践 / Beyond_Unit_Testing_Practical_Java_Development_Techniques_for_Organizing_Requirements_and_Specifications
shimashima35
0
400
キャリア迷子上等 ─ "ない道"は自分で作ればいい
16bitidol
3
2.1k
A2UI という光を覗いてみる
satohjohn
1
130
New "Type" system on PicoRuby
pocke
1
860
例外の正しい扱い方 そのエラー try-catchして大丈夫?
jinwatanabe
0
230
並列実装の現場、2ヶ月間実務でAIを使い倒したAIもPCも私も限界が近い
ming_ayami
0
130
IBM Bobを活用したレガシーアプリの最新化
oniak3ibm
PRO
1
190
[2026年度第1回ORセミナー] 計画最適化ベンチャーと競技プログラミング人材
terryu16
0
260
「エンジニアインターン、どうやって取った?」準備のリアルを語るLT会 Progate BAR
akiomatic
0
130
正しくソフトウェアを作る、前提を疑うための認知の視点 / doubt-premise
minodriven
21
6.6k
Featured
See All Featured
VelocityConf: Rendering Performance Case Studies
addyosmani
333
25k
Google's AI Overviews - The New Search
badams
0
1k
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.3k
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
610
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
160
Fashionably flexible responsive web design (full day workshop)
malarkey
408
66k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
Applied NLP in the Age of Generative AI
inesmontani
PRO
4
2.3k
Documentation Writing (for coders)
carmenintech
77
5.4k
Claude Code どこまでも/ Claude Code Everywhere
nwiizo
65
56k
The Curious Case for Waylosing
cassininazir
1
380
Transcript
Mithril の紹介 A Javascript Framework for Building Brilliant Applications esm_LT
2017-03-03 村上 雅彦 @fossamagna
村上 雅彦 a.k.a @fossamagna 株式会社 永和システムマネジメント IT サー ビス事業部所属 2
Mithril を知ってますか? 3
Mithril SPA 向けのクライアントサイドのJavaScript フレー ムワー ク 4
Mithril の特徴 シンプルなAPI サイズが小さい(gzip で < 8kb) パフォー マンス高い VirtualDOM
ラウター もある 依存ライブラリがない IE9 までサポー ト(poly ll は必要なし) 5
Mithril のバー ジョン 最新は1.0.1 (2017-02-09) 0.2.5 (2016-05-27) 以前とは互換性がない部分があ るので、 そのままではまず動かない。
0.2.x からはマイグレー ションガイドを見て1.0.x に移行しましょう。 6
Mithril のバー ジョン 最新は1.0.1 (2017-02-09) 今日はここ。 0.2.5 (2016-05-27) 以前とは互換性がない部分があ るので、
そのままではまず動かない。 0.2.x からはマイグレー ションガイドを見て1.0.x に移行しましょう。 7
Hello World <body> <script src="//unpkg.com/mithril/mithril.js"></script> <script> var root = document.body;
// これでbody のテキストとして Hello world が描画される。 m.render(root, "Hello world"); </script> </body> m.render() で描画処理が実行されて画面に Hello world が表示される。 render() の第2 引数にはVDOM オブジェクトを指定 する。 8
View の定義 m.render() に渡すVDOM(Mithril ではvnode) はm() 関数(Hyperscript) で定義する。 シグネチャは m('
タグ名', ' 属性オブジェクト', '[ 子要素]') 。 以下のような感じで書いていく。 m.render(root, m("main", [ m("h1", {class: "title"}, "My first app"), m("button", "A button"), ])); 9
JXS でも書ける JXS を利用してHTML のシンタックスでも書ける。 m.render(root, <main> <h1 class="title">My first
app</h1> <button>A button</button> </main>); 10
JXS の使い方 Babel のtransform-react-jsx のpragma オプションで m() 関数を利用するように指定。 .babelrc の例
{ "presets": ["es2015"], "plugins": [ ["transform-react-jsx", { "pragma": "m" // これ大事! }] ] } 11
コンポー ネントも作れる var count = 0; var Hello = {
view: function() { return m("main", [ m("h1", {class: "title"}, "esm_LT"), // changed the next line m("button", {onclick: function() {count++}}, count + " clicks"), ]); } }; // mount 関数を呼び出して自動描画システムを有効にする m.mount(root, Hello); 12
自動描画システム 自動描画システムを有効にすると以下の条件の時に Mithril が描画処理を実行する。 UI イベント処理後(DOM イベントハンドラの呼び出 し後) HTTP リクエストの完了後
ラウティングの後 次のようにして自動描画システムを有効にできる m.mount(root, Hello); // or m.route(root, '/', {'/': Hello}); 13
HTTP リクエスト m.request({ method: "PUT", url: "/api/v1/users/:id", data: {id: fossamagna,
name: "MURAKAMI Masahiko"} }) .then(function(result) { console.log(result); }); Promise を返す。 Promise の処理が全て終わったら自動で描画が実行 される( 自動描画システムが有効なら)。 14
ラウター の定義 var Hello = { view: function() { return
'Hello'; } }; var UserPage = { view: function(vnode) { // ラウティングパラメー タが // vnode.attrs のプロパティにマッピングされる return 'Hi ' + vnode.attrs.id + '!'; } }; m.route(root, "/hello", { "/users/:id": UserPage, // :id の部分がパラメー タ "/hello": Hello }); 15
ラウター の利用 遷移 // fossamagna のペー ジに遷移 m.route.set('/users/fossamagna'); // または
m.route.set('/users/:id', {id: 'fossamagna'}) 画面の描画 Hi fossamagna! 16
ラウター の利用 現在のパスを取得 var path = m.route.get(); console.log(path); > /users/fossamagna
17
まとめ 依存ライブラリなしで入れやすい シンプルなAPI で学習しやすい 問題が起きても対処しやすいと思う( いざとなっ たらコー ドも読める分量) でも、 必要な物は揃っている
18
ぜひ、 Mithril をお試しあれ! 19