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
MURAKAMI Masahiko
March 02, 2017
Programming
0
220
Mithrilの紹介/Introduce of Mithril
MURAKAMI Masahiko
March 02, 2017
Tweet
Share
More Decks by MURAKAMI Masahiko
See All by MURAKAMI Masahiko
Amplify Gen2を 拡張してみよう JAWS-UG北陸新幹線 ( 福井開催 ) 2024-04-06/Let's extend Amplify Gen2
fossamagna
0
300
みんな本当に AWS Amplify を知っている?/do-you-really-know-aws-amplify
fossamagna
0
93
Amplify OSSにコントリビュートしてAmplify Badgeを手に入れよう!/contribute-to-amplify-oss-and-get-an-amplify-badge
fossamagna
0
200
Using custom function template with AWS Amplify
fossamagna
1
360
Amplifyで始めるサーバレス開発/serverless-development-starting-with-amplify
fossamagna
0
1.4k
拡張して使うServerless&Amplify/use-with-extending-serverless-and-amplify
fossamagna
0
1.1k
JavaScript AST
fossamagna
0
1.7k
Electronで製造ラインアプリ開発/Business application by Electron
fossamagna
4
6.7k
Apps Scriptによるより高度な開発プロセス/More Advanced Development Process with Apps Script
fossamagna
3
2.3k
Other Decks in Programming
See All in Programming
GitHub Copilotのススメ
marcy731
1
200
VS Code をプロダクトにどう取り込むか
onomax
1
360
"config" ってなんだ? / What is "config"?
okashoi
0
240
Git Lint
bkuhlmann
4
750
PHPはいつから死んでいるかの調査
chiroruxx
1
400
デフォルトにして至高、RubyMineの大好きな所
ruzia
0
380
Zero Waste, Radical Magic, and Italian Graft – Quarkus Efficiency Secrets
hollycummins
0
230
ADRを一年運用してみた/adr_after_a_year
hanhan1978
7
2.4k
サイコロで理解する統計的仮説検定の考え方
tatamiya
4
930
if constexpr文はテンプレート世界のラムダ式である
faithandbrave
3
650
検証も兼ねて個人開発でHonoとかと向き合った話
hanetsuki
1
920
educure_カリキュラム生操作マニュアル.pdf
linew_official
0
790
Featured
See All Featured
Building Effective Engineering Teams - LeadDev
addyosmani
28
1.8k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
121
39k
Bootstrapping a Software Product
garrettdimon
PRO
302
110k
Building Adaptive Systems
keathley
31
1.9k
Thoughts on Productivity
jonyablonski
58
3.8k
Large-scale JavaScript Application Architecture
addyosmani
504
110k
Keith and Marios Guide to Fast Websites
keithpitt
408
22k
Producing Creativity
orderedlist
PRO
337
39k
Why You Should Never Use an ORM
jnunemaker
PRO
51
8.6k
Imperfection Machines: The Place of Print at Facebook
scottboms
260
12k
Statistics for Hackers
jakevdp
789
220k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
221
21k
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