Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Flux アーキテクチャの話
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
popkirby
July 29, 2015
460
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Flux アーキテクチャの話
W8LT #4の資料
popkirby
July 29, 2015
Featured
See All Featured
Believing is Seeing
oripsolob
1
240
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
10k
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
410
How STYLIGHT went responsive
nonsquared
100
6.3k
YesSQL, Process and Tooling at Scale
rocio
174
15k
GraphQLとの向き合い方2022年版
quramy
50
15k
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
3
280
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
460
A better future with KSS
kneath
240
18k
Tell your own story through comics
letsgokoyo
1
1.1k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
730
Transcript
Flux ΞʔΩςΫνϟͷ W8LT#04 @popkirby
ࣗݾհ @popkirby ౦େB4ɾJK → ͔͚ͣ͢ͷຽ TwitterͰήʔϜͱΞΠυϧϚελʔ γϯσϨ ϥΨʔϧζͷ͔ͯ͠͠·ͤΜ
Flux ͬͯԿʁ
Flux • Application Architecture for Building User Interfaces • https://github.com/facebook/flux
• MV* ͱ͔Έ͍ͨͳGUI ϓϩάϥϛϯάͷ ύλʔϯ • Web ΞϓϦέʔγϣϯ ͚
MVC • Model: σʔλ/ϏδωεϩδοΫ • View: UI • Controller: ೖྗ͔ΒؤுΔϚϯ
……M, V, C ؒ Ͳ͏ͳͬͯΔͷʁ
MVC ͷҋ • M, V, Cͷఆ͚͕ٛͩҰਓา͖ͯͦ͠ΕͧΕͷؒ ͷ௨৴ํ๏͕·͍ͬͯͳ͍ • View
Model ΛݟΔ͜ͱ͕Ͱ͖Δͷ͔ʁ • View Model Λߋ৽Ͱ͖Δͷ͔ʁ • → ܾ·ͬͨఆ͕ٛཉ͍͠
MVC ͷҋ • MVC ͷੜܥ͕ଟ͗ͯࠞ͢ཚ͢Δ(Ҽԑ) • MVP: Presenterͱ͍͏ϒϥοΫࣾһΛಋೖ • MVVM:
ViewModel(MVͷؒΛ͍͍ײ͡ʹͱΓͬ ͨΓɺViewͷঢ়ଶΛͬͨΓ)ΛՃ • MVW: WhateverͰ͍͍͡ΌΜɺMVCʹ͍ͭͯߟ͑ ΔͷΛΊΖɺͦΜͳՋ͕͋ΕίʔυΛॻ͚
FluxΛ͔ͭ͏
Flux ͱ • Action -> Dispatcher -> Store -> View
-> Action -> … ͷྲྀΕΛఆٛ
Action • Ϣʔβͷೖྗ ֎෦ͱ ͷ௨৴͔Β࡞ΒΕΔ • ʮͲͷΑ͏ͳछྨͷૢ ࡞/௨৴͕ߦΘΕ͔ͨʯ ͱ͍͏ใͱσʔλΛ ࣋ͭΦϒδΣΫτ
• Dispatcherʹ͞ΕΔ // ActionCreator function increment(count) { AppDispatcher.dispatch({ type: INCREMENT_COUNTER, count }); }
Dispatcher • ड͚औͬͨ Action ͷछྨʹରԠ͢Δ Store ͷίʔϧόο ΫΛݺͼग़͢ // Πϝʔδ
class Dispatch { register(cb) { this.callbacks.push(cb); } dispatch(action) { for (let cb in this.callbacks) { cb(action); } } }
Store • σʔλɾϏδωεϩδοΫΛ ࣋ͭ • Dispatcher ͔Βड͚औͬͨ௨ Λར༻ͯ͠σʔλΛߋ৽ • ͜ΕҎ֎ʹσʔλΛߋ৽͢
Δํ๏ͳ͍ • σʔλ͕ߋ৽͞ΕͨΒ View ʹ௨ // Πϝʔδ let counter = 0; const CounterStore = { getCounter() { return counter; } emitChange() { … } addChangeListener(cb) { … } }; AppDispatcher.register((action) => { switch(action.type) { case INCREMENT_COUNTER: counter += action.count; CounterStore.emitChange(); break; } });
View • Store Λݟͯ UI Λͭ͘ Δ • Ϣʔβ͔ΒͷೖྗΛड ͚औͬͨΒ
Action Λ ࡞ͬͯ Dispatcher ʹ ͛Δ class CounterApp extends Component { constructor() { CounterStore.addChangeListener(this.onChange); } onChange = () => { this.setState({ counter: CounterStore.getCounter() }); } handleIncrement(counter) { CounterActions.increment(counter); } render() { return ( <Counter counter={counter} increment={::this.handleIncrement} /> } }
Flux ͷ͏Ε͍͠ͱ͜Ζ • ྲྀΕ͕Ұํ • ํσʔλόΠϯσΟϯάਓྨʹૣ͔ͬ ͨ(anguͳΜͱ͔lar) • ୯७ •
ڈ7݄ʹൃද͞Ε͔ͯΒ݄20ݸϖʔεͰΦϨΦ Ϩ࣮͕༙͍͖͍ͯͯΔ
demo https://github.com/popkirby/flux-sushi-counter/
͍ͭͰʹ • ࣮ Flux ࣮࣭తʹ MVC ͱ·ͬͨ͘ಉ͡ • ͍ΘΏΔSmallTalk MVC
• JavaScript ͕ Web ΞϓϦͷϩδοΫΛ୲Ͱ͖ΔΑ͏ʹ ͳͬͯ෮׆ • ͦΕͧΕͷཁૉؒͷؔΛڧௐ͍ͯ͠Δ • ΦϒδΣΫτࢦΦϒδΣΫτ͚ͩ͡Όͳ͍ͱࣅ͍ͯΔ
͍ͭͰʹ • ࠷ۙReduxͱ͍͏࣮͕ؾʹͳͬͯ·͢ • ؔܕͷߟ͑ΛऔΓೖΕͯΔΒ͍͠ • Store: (beforeState, action) ->
afterState • View Store ͷࣸ૾