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
200
クックパッドマート 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
社内での開発コミュニティ活動とモジュラーモノリス標準化事例のご紹介/xPalette and Introduction of Modular monolith standardization
m4maruyama
1
130
地方に住むエンジニアの残酷な現実とキャリア論
ichimichi
2
540
生成AIコーディングとの向き合い方、AIと共創するという考え方 / How to deal with generative AI coding and the concept of co-creating with AI
seike460
PRO
1
320
エンジニア向け採用ピッチ資料
inusan
0
140
XSLTで作るBrainfuck処理系
makki_d
0
210
Javaのルールをねじ曲げろ!禁断の操作とその代償から学ぶメタプログラミング入門 / A Guide to Metaprogramming: Lessons from Forbidden Techniques and Their Price
nrslib
3
2k
GoのGenericsによるslice操作との付き合い方
syumai
2
670
DroidKnights 2025 - 다양한 스크롤 뷰에서의 영상 재생
gaeun5744
3
300
Rails産でないDBを Railsに引っ越すHACK - Omotesando.rb #110
lnit
1
170
つよそうにふるまい、つよい成果を出すのなら、つよいのかもしれない
irof
1
290
データの民主化を支える、透明性のあるデータ利活用への挑戦 2025-06-25 Database Engineering Meetup#7
y_ken
0
260
アンドパッドの Go 勉強会「 gopher 会」とその内容の紹介
andpad
0
250
Featured
See All Featured
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
161
15k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
16k
It's Worth the Effort
3n
184
28k
Rails Girls Zürich Keynote
gr2m
94
14k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
32
5.9k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
16
940
Automating Front-end Workflow
addyosmani
1370
200k
Why Our Code Smells
bkeepers
PRO
337
57k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
281
13k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
3.9k
Stop Working from a Prison Cell
hatefulcrawdad
270
20k
The Cult of Friendly URLs
andyhume
79
6.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