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
AngularJSでのComponent指向
Search
imashin
June 19, 2015
Programming
0
370
AngularJSでのComponent指向
ng-kyoto Meetup Kyoto #1
imashin
June 19, 2015
Tweet
Share
More Decks by imashin
See All by imashin
スマートホームのこれから - NOT A HOTEL TECH TALK 2024/04/09
shinsuke_imai
1
210
クックパッドマート SORACOMを使って 高速プロトタイピング
shinsuke_imai
0
69k
クックパッドマート開発の裏側 ~ステーション編~
shinsuke_imai
0
1.5k
クックパッドマートを支えるIoT 技術
shinsuke_imai
0
570
クックパッドマートを支えるIoT 技術
shinsuke_imai
0
1.2k
Reliable distribution system with Ruby x IoT
shinsuke_imai
0
730
クックパッド流食品流通の作り方
shinsuke_imai
0
280
Reliable label printer system
shinsuke_imai
0
220
Data analysis of cookpad storeTV
shinsuke_imai
1
5.7k
Other Decks in Programming
See All in Programming
LINEヤフー データグループ紹介
lycorp_recruit_jp
0
1.6k
NPOでのDevinの活用
codeforeveryone
0
480
Cursor AI Agentと伴走する アプリケーションの高速リプレイス
daisuketakeda
1
130
0626 Findy Product Manager LT Night_高田スライド_speaker deck用
mana_takada
0
130
イベントストーミング図からコードへの変換手順 / Procedure for Converting Event Storming Diagrams to Code
nrslib
1
550
アンドパッドの Go 勉強会「 gopher 会」とその内容の紹介
andpad
0
280
Modern Angular with Signals and Signal Store:New Rules for Your Architecture @enterJS Advanced Angular Day 2025
manfredsteyer
PRO
0
160
Create a website using Spatial Web
akkeylab
0
310
AWS CDKの推しポイント 〜CloudFormationと比較してみた〜
akihisaikeda
3
320
20250704_教育事業におけるアジャイルなデータ基盤構築
hanon52_
1
120
ReadMoreTextView
fornewid
1
490
既存デザインを変更せずにタップ領域を広げる方法
tahia910
1
250
Featured
See All Featured
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
17
950
XXLCSS - How to scale CSS and keep your sanity
sugarenia
248
1.3M
Why You Should Never Use an ORM
jnunemaker
PRO
58
9.4k
Building Adaptive Systems
keathley
43
2.6k
jQuery: Nuts, Bolts and Bling
dougneiner
63
7.8k
GraphQLの誤解/rethinking-graphql
sonatard
71
11k
GraphQLとの向き合い方2022年版
quramy
49
14k
[RailsConf 2023] Rails as a piece of cake
palkan
55
5.6k
How GitHub (no longer) Works
holman
314
140k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
161
15k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
48
5.4k
Transcript
+ AngularJS での Component 指向 bindToControllerとかの話も添えて 20min ng-kyoto Meetup #1
+ MENU n ⾃自⼰己紹介 n AngularJSでのDirective指向とは n bindToControllerとは
+ ⾃自⼰己紹介 今井 晨介 @shin_v1 shinsuke.imai1 shinsukeimai
+ ⾃自⼰己紹介 n 京都 n ⼤大学院修⼠士1年年 n ラクロス n 可視化研究
+ ⾃自⼰己紹介 n ⼈人前で話すの初めて n お⼿手やらわかに
+ 制作物 n ラクロス可視化分析ツール
+ MENU n ⾃自⼰己紹介 n AngularJSでの Directive指向とは n bindToControllerとは
+ 今⽇日話すこと 主に Directiveの扱い⽅方
+ 今⽇日話すこと Custom Directive で SPAを作る
+ AngularJS n Data Binding n Template Engine n Ajax Support n Routing n Test
n Security 今⽇日のメインテーマ <my-template></my-template>
+ Template Engine テンプレートエンジン って何すか
+ Template Engine View <my-hoge> </my-hoge> <div></div> <my-directive> </my-directive>
+ Directive <my-directive> </my-directive> Custom Directive View <my-hoge> </my-hoge>
<my-foo> </my-foo> <my-directive> </my-directive>
+ Directive 複数の Custom Directive を 組み合わせる <my-foo></my-foo> <my-directive> </my-directive>
<my-hoge></my-hoge>
+ Custom Directive化の指針 実際にアプリを作ることを 想定して Directive の扱いを網羅羅
+ Custom Directive化の指針 本⽇日のたたき台 Slack @ng-kyoto をAngularJS 1.4 で作るなら
+
+ Custom Directive化の指針 どうやって分割するのか 冪等性? Testable? Maintenacebility? 視認性? Readability?
+ Custom Directive化の指針 <sk-navbar></sk-navbar> <sk-topics> </sk-topics> <sk-send-message></sk-send-message> <sk-messages> </sk-messages>
+ Custom Directive化の指針 1. one Function in one Directive 2.
Reusable or not 3. No logic code 4. Independence
+ one Function in one Directive n one Function in one
Directive n Componentに明確な役割を1つ n その役割に合わせて要素の命名 <im-navbar></im-navbar> < {{プロジェクト接頭語}} – {{役割}} > <data-im-navbar></data-im-navbar> 1
+ one Function in one Directive 1 n 保守性があがる n 役割が明確になる n コードが短くなる
n 読みやすくなる n テストしやすい n 誰が書いてもだいたい同じ物
+ one Function in one Directive <sk-navbar></sk-navbar> <sk-topics> </sk-topics> <sk-send-message></sk-send-message>
<sk-messages> </sk-messages> 1
+ one Function in one Directive 1 n 例例えば navigation bar
の場合 n <im-navbar></im-navbar> n これはナビバーの複数のDirectiveを 内包するDirective
+ one Function in one Directive 1 n 例例えば navigation bar
に含まれる検 索索Directiveの場合 n <sk-search></sk-search> n これの役割はinputをServiceに伝える
+ one Function in one Directive 1 n 検索索バーを別の場所にすぐ移せるよ うにするには n Style
は分離離する。
+ Reusable or not n Reusable or not n 再利利⽤用可能なものって結構少ない。 n Ex) ナビバー、ボタン、パネル、ア
イコン etc… n 再利利⽤用可能な物って作るの難しい。 n 再利利⽤用可能ってもうライブラリ 2
+ Reusable or not n Reusable or not n 作り始めに再利利⽤用する、しないを決 めておく。 n 同じプロジェクトで再利利⽤用するのか、
他のプロジェクトでも使うのか。 n Reuseできたら楽なときもある。 2
+ Reusable or not n Reusable or not n https://github.com/likr/shinsekai n 参考に n SVG操作を抽象化
2
+ Reusable or not <sk-navbar></sk-navbar> <sk-topics> </sk-topics> <sk-send-message></sk-send-message> <sk-messages> </sk-messages>
2
+ Component化の指針 繰り返されるもの
+ Reusable or not <sk-messages> </sk-messages> <sk-message></sk-message> <sk-message></sk-message> <sk-message></sk-message> <sk-message></sk-message>
<sk-message></sk-message> <sk-message></sk-message> <sk-message></sk-message> <sk-message></sk-message> <sk-message></sk-message> 2 ng-repeat
+ Reusable or not <sk-message></sk-message> icon name time <sk-text></sk-text> <sk-text></sk-text>
text mention link 2
+ Reusable or not n 指針 n 決められた型のデータが⼊入ってきたら n いつでも同じものを出⼒力力 n ⾃自然とそうなるはず 2
+ No logic n No logic n ロジックコードはService ( service, factory )で書こう
3
+ No logic n Directiveの役割 n データを受け取って、Templateに 流流し込む n 何かのUser Actionがあった時、 Serviceに伝える 3
+ No logic 3 Directive Business logic DB Cache Directive
Business logic Web API
+ No logic 3 n Ex) n Directive はinputを受けとって、検索索 Serviceへ値を渡す。
+ Independence n Independence n 依存性をできうる限り無くす n 依存とは。 n Input n Output 4
+ Independence n Input n データを外から受け取る⽅方法 n 1, Service経由 n 2, attr経由のbind 4
+ Independence n 1, Service経由(DI) n 基本的にViewで描画するデータは Serviceから受け取るようにしている。 4 Directive Business logic
DB Cache
+ Independence 4
+ Independence 4
+ Independence n 2, attr経由のbind n ng-repeatの時よく使う。 4 ⼦子のDirective 親の Directive ⼦子のDirective
⼦子のDirective
+ 親のDirective ⼦子のDirective Independence 4 <div ng-repeat="(key, message) in threads.messages">
<sk-thread msg="message" key="key"></te-thread> </div>
+ Independence n Output n 1, Serviceにdataを渡す n 2, ⼦子Directiveにdataを渡す 4
+ Independence n 1, Serviceにdataを渡す 4 Directive $resource Service Server
+ Independence n 依存性をなくす n = NavBar でなくても動作する n (ex, Model へすぐに移⾏行行可能 4
+ Independence n 2, ⼦子Directiveにdataを渡す n Inputと同じ n ng-repeat を使う時⽤用いる n ng-repeat した⼦子Directive 4
+ まとめ n ⼀一つのDirectiveに⼀一つの役割 n Directiveが値を保持しない(Serviceを利利⽤用) n 依存性を無くして、疎結合に
+ MENU n ⾃自⼰己紹介 n AngularJSでのComponents志向 とは n bindToControllerとは
+ bindToController n What is bindToController n 1.4からの新機能() "bind to controller” ===
"bind an isolated scope to a controller"
+ bindToController n Directiveって⼊入れ⼦子になります n 親から attr 経由で値を引き継ぐ
+ bindToController n これまでは$scopeを⽤用いて Controllerで値をbindしていた。 n Controllerの thisにbind可能
+ bindToController thisにbind Do something: clicked(){ alert(this.msg); } 必須
+ bindToController n 注意 n bindToController使えへんやんけ n controllerAs書いていますか? n scope: {}って書いていますか? n AngularJSのバージョンは1.4.x? n キャメルケースとハイフンケース
+ bindToController n もっと詳しく知りたい⼈人は 「AngularJS1.4 と bindToController」
+ 終わり Thank you