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
Chaplin.jsの話 #ten1club
Search
Koutarou Chikuba
July 11, 2014
3
7.7k
Chaplin.jsの話 #ten1club
Chaplinの話!!!
Koutarou Chikuba
July 11, 2014
Tweet
Share
More Decks by Koutarou Chikuba
See All by Koutarou Chikuba
極限環境で最終ビルドを絞るためのフロントエンド設計
mizchi
15
4.8k
Server Side JavaScript のためのバンドル最適化
mizchi
5
6.5k
V8 as a container on CDN Edge worker
mizchi
6
1.9k
Edge Side Frontend という新領域
mizchi
34
14k
バンドル最適化マニアクス at tfconf
mizchi
7
4.2k
「たかがJavaScript」のその先 #TECHPLAY
mizchi
47
20k
Deno Node 両刀
mizchi
6
2.3k
「フロントエンド領域」を再定義する
mizchi
50
36k
光を超えるためのフロントエンドアーキテクチャ
mizchi
90
23k
Featured
See All Featured
Building an army of robots
kneath
302
43k
Rebuilding a faster, lazier Slack
samanthasiow
79
8.7k
It's Worth the Effort
3n
183
27k
Designing Experiences People Love
moore
138
23k
Happy Clients
brianwarren
98
6.7k
Side Projects
sachag
452
42k
Mobile First: as difficult as doing things right
swwweet
222
8.9k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
131
33k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.1k
Teambox: Starting and Learning
jrom
133
8.8k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
Transcript
Chaplin.jsͷ @mizchi'/'#ten1club
None
ࣗݾry#͙͙Ε
Chaplin.jsͱ • paulmillr࡞ͷBackbone֦ுܥMVCϥΠϒϥϦ • paulmillrࢯɺAc4vity͕ଟ͍ͷͰ͍ΖΜͳͱ͜ͰݟΔ • Rails෩ͷઃܭͰSPAΊΔ
Rails෩ͷߏ ~/s/bwc (master) $ la app/ total 32 drwxr-xr-x 11
mizchi staff 374B 7 11 16:33 . drwxr-xr-x 10 mizchi staff 340B 7 11 16:33 .. -rw-r--r-- 1 mizchi staff 207B 7 11 16:33 application.coffee drwxr-xr-x 4 mizchi staff 136B 7 11 16:33 assets drwxr-xr-x 5 mizchi staff 170B 7 11 16:34 controllers -rw-r--r-- 1 mizchi staff 230B 7 11 16:33 initialize.coffee drwxr-xr-x 4 mizchi staff 136B 7 11 16:33 lib -rw-r--r-- 1 mizchi staff 45B 7 11 16:33 mediator.coffee drwxr-xr-x 3 mizchi staff 102B 7 11 16:33 models -rw-r--r-- 1 mizchi staff 75B 7 11 16:33 routes.coffee drwxr-xr-x 8 mizchi staff 272B 7 11 16:35 views ͋͘·ͰRailsʮ෩ʯͰ͋ͬͯͦͷͷͰͳ͍
ࣗͱChaplin.js • ϓϩμΫγϣϯͰ2ϓϩδΣΫτͰ༻ • ศརͳ໘ෆຬ͋Δ • Γͳ֦ͯ͘ுͯͬͯ͠Δ
ࠓ͠ΌΔ͜ͱ • ओʹBackboneʹͳ͍ػೳʹ͍ͭͯ • ViewͱModelࢮ׆ཧ͞ΕͯΔ͜ͱҎ֎Ұॹ
Chaplinͷઃܭ
None
ಛ • Rails෩Router • Πϯελϯεͷੜ/ഁغΛཧ͢ΔComposer • ಛԽͨ͠ϏϧυγεςϜ(brunch) • Rails෩εΩϟϑΥϧσΟϯά(scaffolt)
Composer
Composer • Controllerͱڠௐͯ͠Πϯελϯεཧ͢Δ • ϧʔςΟϯάΞΫγϣϯຖʹ͋ΒΏΔΠϯελϯεͷdispose͕ ݺΕΔ • ControllerͷΓସΘΓલޙͰ-reuse-ͨ͠ͷҾ͖ܧ͕ΕΔ
Controller/Composerͷྫ # controllers/home-controller module.exports = class HomeController index: -> layout
= @reuse('layout', LayoutView) view = @reuse('home', HomeView) # controllers/foo-controller module.exports = class FooController index: -> layout = @reuse('layout', LayoutView) view = @reuse('foo', FooView) Home%&>%Foo%ͷભҠͰ%Layout%ফ͑ͳ͍
ComposerͲ͏ͳͷ • ϝϦοτ • ࠩཧͰը໘ͷߏங͕͍ • σϝϦοτ • ʮΠϯελϯε͕Ҿ͖ܧ͕Ε͍ͯΔʯͱ͍͏ͷΛҙࣝ͠ͳ͍ ͱେʹόάΔ
• ΠϕϯτίʔϧόοΫෳճషͬͯͨΓɺ͍͠…
൪֎ ʮdispose࣋ͬͯΔΠϯελϯεΛreuse͢ΔͱɺભҠͯ͠Θͳ ͍࣌ʹࣺͯΔʯͱ͍͏Έ͚ͩਅࣅͨ͠ϧʔλʔ࡞ͬͨ h"ps:/ /github.com/mizchi/warden ओʹvue.js༻ɻझຯϓϩμΫτͰͬͯΔ͚Ͳศརɻ
Generator
Generator • paulmillr/scaffolt • Railsͷscaffoldͱࣅͨײ͡ • σΟϨΫτϦن͕͔ͬ͠Γ͋Δ͔Β࣮ݱͰ͖Δ • handlebars1ͰίʔυͷܗΛॻ͍ͯੜ
Generatorͷ༻ྫ ~/s/mizchi-bwd (master) $ scaffolt scaffold foo 11 Jul 16:36:34
- info: init app/templates/foo 11 Jul 16:36:34 - info: create app/templates/foo/foo.jade 11 Jul 16:36:34 - info: create app/controllers/foo-controller.coffee 11 Jul 16:36:34 - info: create test/controllers/foo-controller-test.coffee 11 Jul 16:36:34 - info: init app/view-models/foo 11 Jul 16:36:34 - info: init test/view-models/foo 11 Jul 16:36:34 - info: init app/views/foo 11 Jul 16:36:34 - info: init test/views/foo 11 Jul 16:36:34 - info: init app/styles/foo 11 Jul 16:36:34 - info: create app/view-models/foo/foo-view-model.coffee 11 Jul 16:36:34 - info: create test/view-models/foo/foo-view-model-test.coffee 11 Jul 16:36:34 - info: create app/views/foo/foo-view.coffee 11 Jul 16:36:34 - info: create test/views/foo/foo-view-test.coffee 11 Jul 16:36:34 - info: create app/styles/foo/foo.sass
GeneratorͲ͏ͳͷ • ͱʹ͔͘MV*ͳΜͨΒΔͱϑΝΠϧ͕૿͑Δ • େ͖ͳϓϩδΣΫτͳΒܗඞਢ • ࣮Chaplinͱؔͳ͍ͷͰಠཱͯͬͯ͠Α͍ • ϑΥʔΫͨ͠,mizchi/scaffolt,͏ͱແݶʹҾͱΕͯศར
Collec&onView
Collec&onView • Backbone.Collec-onʹରԠͯ͠ViewΛੜ͢Δ • ৄ͘͠ઌिͨ͠ࢿྉΈ͍ͯͩ͘͞ • ʮ͓લࣗͪͷϖʔδϟUI͕ຊʹ͍ͱࢥͬͯΜͷʁ3ʯͰ ݕࡧ
Collec&onViewͲ͏ͳͷ(ཁ) • Collec'onૢ࡞ͰView͕ੜ͞Εͯศར • ϦετϏϡʔ͕ωετͨ͠߹ɺཧ͕ࠔ
Brunch
Brunch • ΣϒΞϓϦέʔγϣϯʹಛԽͨ͠Ϗϧυϥϯφʔ ―#common.js෩ͷrequire#+#֦ுࢠʹΑΔࣗಈల։ • npmͰ֦ுࢠʹԠͨ͡ϓϥάΠϯೖΕΔ#or#ॻ͘ • ࣮Chaplinͱؔͳ͍(͚Ͳεέϧτϯ͕͜ΕͰॻ͔ΕͯΔͷͰ ͏ͱָ)
BrunchͲ͏ͳͷ • Grunt/Gulpʹ͔ͬΕͳ͍ͷ͕ਏ͍ • ϓϥάΠϯ͍͍ͩͨॻ͔ͳ͍ͱ͍͚ͳ͍ • ࠷ۙGulpʹ͠·ͨ͠
chaplin.jsͷਏ͍ • ྑ͘ѱ͘paulmillrϫʔϧυ • brunch • scaffolt • ಠࣗcommon.js •
શମతʹγϯάϧτϯͷmediatorʹີ݁߹Ͱ୯ମςετࠔ • ࡞ऀ͋Μ·Γςετͯ͠ͳͦ͞͏ͳͷͰؾ͍ͮͯͳ͍…
࣮ӡ༻ͰͷChaplin.jsͷ֦ு
MVVM෩ʹσʔλόΠϯυ͢Δʂ • ViewʹmodelҾ͕ͳ͍߹ɺۭͷϞσϧΛࣗಈੜ • ίϯτϩʔϥ͔ΒϏϡʔϞσϧૢ࡞ • ੲ͜͏͍͏ͷΛॻ͍ͨͷͰࢀߟʹ • ʮBackboneͰσʔλόΠϯσΟϯάΛͬͯMVVMΛ͢Δϑ ϩϯτΤϯυΞʔΩςΫνϟʯ
Backbone.s+ckit • NYTBackboneσʔλόΠϯυ • NYTimes/backbone.s2ckit bindings: { '#album': { observe:
'Tomorrow\'s Harvest', destroy: function($el, model, options) { // Tear down any events or clean up. } } }
mocha&phantomjs,Ͱςετ • ViewͱModelςετॻ͍ͨ • Controllerγϯάϧτϯͱີ݁߹͍ͯͯ͠ఘΊͨ
Chaplin͔Βಘֶͨͼ • σΟϨΫτϦߏͷن࡞ͬͯδΣωϨʔλʔॻ͚։ൃര • ϢχοτςετϑϨʔϜϫʔΫͱີ݁߹͢ΔͷͰϑϨʔϜϫ ʔΫબఆʹӨڹ͢Δ • ϦετϏϡʔΛ؆୯ʹॻ͚ΔϑϨʔϜϫʔΫҒ͍
ChaplinΛ࠾༻͢ΔՁ͕͋Δέʔε • RailsΤϯδχΞ͕ଟ͍ • Backbone͕Γͳ͍
࣍ͷϓϩδΣΫτʁ • ࣗBackbone/Chaplin͖ͨͷͰ0vue.js0͔0react.js0Ͱ͢
͓͠·͍