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
Inside Bdash
Search
Kazuhito Hokamura
March 16, 2017
Technology
840
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Inside Bdash
Kazuhito Hokamura
March 16, 2017
More Decks by Kazuhito Hokamura
See All by Kazuhito Hokamura
TypeScriptとGraphQLで実現する 型安全なAPI実装 / TSKaigi 2024
hokaccha
5
5.1k
Kotlin製のGraphQLサーバーをNode.jsでモジュラモノリス化している話
hokaccha
0
3.8k
GraphQLの負債と向き合うためにやっていること
hokaccha
2
1.6k
ユビーのアーキテクチャに対する取り組み
hokaccha
1
490
RailsエンジニアのためのNext.js入門
hokaccha
7
22k
Cookpad Summer Internship 2021 Web Frontend
hokaccha
0
7.4k
巨大なモノリシック Rails アプリケーションの マイクロサービス化戦略 / 2019 microservices in cookpad
hokaccha
3
4.1k
巨大なRailsアプリケーションを「普通」にするための取り組み
hokaccha
1
1.1k
Web Frontend Improvement in Cookpad
hokaccha
1
1.2k
Other Decks in Technology
See All in Technology
41歳でAWSが好きすぎてITエンジニアになったおっさんの話
yama3133
1
770
Webアプリ認証の全体像 / The Big Picture of Web App Authentication
kitano_yuichi
1
450
発表と総括 / Presentations and Summary
ks91
PRO
0
210
クラウドを使う側から、作る側へ / 大吉祥寺.pm 2026前夜祭
fujiwara3
6
1.4k
論語・武士道・産業革命から見る かわるもの、かわらないもの
ichimichi
7
820
複数プロダクト組織のAIネイティブ化における戦略 / AICon2026_kude
rakus_dev
0
310
OPENLOGI Company Profile for engineer
hr01
1
75k
キャリアLT会#3
beli68
2
260
現場との対話から始める “作る前に問い直す”業務改善
mochico50
2
290
AI時代こそ、スケールしないことをしよう -「作る人」から「なぜ作るか」を考える人へ / Do Things That Don't Scale in the AI Era — From How to Why
kaminashi
1
130
AI時代におけるエンジニアの新たな役割──FDEとクオリアの探求/登壇資料(戸井田 裕貴)
hacobu
PRO
0
380
AI研修(Day2)【MIXI 26新卒技術研修】
mixi_engineers
PRO
1
210
Featured
See All Featured
Prompt Engineering for Job Search
mfonobong
0
380
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
3
1k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
49
10k
SERP Conf. Vienna - Web Accessibility: Optimizing for Inclusivity and SEO
sarafernandez
2
1.5k
Facilitating Awesome Meetings
lara
57
7k
Building a Scalable Design System with Sketch
lauravandoore
463
34k
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
1
2.1k
[RailsConf 2023] Rails as a piece of cake
palkan
59
6.8k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
0
450
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
330
Discover your Explorer Soul
emna__ayadi
2
1.2k
Transcript
Inside Bdash
@hokaccha
None
None
None
None
None
None
None
Flux Architecture of Bdash
Flux Frameworks
Topics • Domain Logicͷݺͼग़͠ • Storeͷׂ • ImmutableʹStateΛߋ৽͢Δ࣮
Domain Logicͷݺͼग़͠
Domain Logic • ඳըʹؔ͢Δ͜ͱҎ֎ͷશͯͷॲཧ • DatabaseͱͷΓऔΓͱ͔ • APIݺͼग़͠ͱ͔ • ઃఆͷཧͱ͔
Ͳ͜ʹ͋Δ͖͔ • Store? • Actino Creator? • Middleware?
None
import { dispatch } from './QueryStore'; import Database from '../lib/Database';
const QueryAction = {}; QueryAction.addNewQuery = params => { Database.Query.create(params).then(query => { dispatch('addNewQuery', { query }); }); }; Action Creator 㲗 Domain Logic
• Domain LogicΛFluxͷϑϩʔ͔Β͢Δ • Action Creator͔Βݺͼग़͚ͩ͢ • StoreStateͷߋ৽͚ͩʹྗ͢Δ
• StoreͱDomain Logicςετ͘͢͠ͳΔ • Action Creator͕ςετͮ͠Β͍ • શ͕ͯPure functionͱ͍͏ͷݬͳͷͰఘΊΔ
Storeͷׂ
ͭ·ΓStateΛͲ͏ׂ͢Δ͔
facebook/flux • Ϧιʔεʁ͝ͱʹStoreΛׂ͢Δ • DispatcherʹΑΔަ௨ཧɺwaitForΛͬͨ ґଘͷղܾ͕ඞཁ
Redux • StoreΛׂ͠ͳ͍ʢSingle Stateʣ • StateΛߋ৽͢ΔॲཧʢreducerʣΛׂ͢Δ • waitForDispatcher͕ෆཁ • State͕ڊେʹͳΔ
Bdash • Page୯ҐͰ͚ͯΈͨ • Page͝ͱʹಠཱͨ͠StoreΛ࣋ͭ • Page == Container Component
Query Page
DataSource Page
Setting Page
None
• Storeಉ࢜ͷґଘ͕ͳ͍ • waitForDispatcherෆཁ • StateΛΘ͔Γཻ͍͢ͰׂͰ͖Δ • શͯPage୯ҐͳͷͰΘ͔Γ͍͢ Good
• PageΛ·͍ͨͩσʔλͷڞ༗͕໘ • ෳͷPageͰಉ͡σʔλΛ࣋ͭ͜ͱ͋Δͷ Ͱແବ͕͋Δ Bad
PageؒͰͷσʔλڞ༗ • PageؒͰڞ༗͢ΔσʔλDomain LogicʹετΞ͢Δ • PageΓସ͑࣌ʹຖճDomain Logic͔ΒऔΓ͢
// Pageͷସ࣌ʹຖճݺΕΔAction Creator QueryAction.initialize = () => { Promise.all([ Database.fetchQueries(),
Database.fetchDataSources() ]).then(([queries, dataSources]) => { dispatch('initialize', { queries, dataSources }); }); }; // Store class QueryStore { reduce(type, { queries, dataSources }) { switch (type) { case 'initialize': { // ߋ৽͚ͩϚʔδ͢ΔͷͰସલͷঢ়ଶอ࣋Ͱ͖Δ return merge(this.state, { queries, dataSources }); } } } }
αʔόʔαΠυͷߟ͑ํ ͱಉͩ͡ɾɾʂ
൚༻తͳઃܭͰͳ͍ ⚠
ΞϓϦέʔγϣϯʹ దͨ͠ઃܭΛɻ
ImmutableͳStateͷߋ৽
let state = { todos: [ { id: 1, text:
'foo' }, { id: 2, text: 'foo' }, ], //... } function updateTodo(state, { id, text }) { return Object.assign({}, state, { todos: state.todos.map(todo => { if (todo.id === id) { return Object.assign({}, todo, { text }); } else { return todo; } }), }); }
• Immutable.jsΈ͍ͨͳ๛ͳػೳ͍Βͳ͍ • ωετͨ͠Stateͷߋ৽Λ؆୯ʹ͍͚ͨͩ͠ • ͍͔ͭ͘ϥΠϒϥϦ͋Δ͚ͲΈʹ߹Θͳ͍
࡞ͬͨ
import immup from 'immup'; let state = { todos: [
{ id: 1, text: 'foo' }, { id: 2, text: 'foo' }, ], //... } function updateTodo(state, { id, text }) { let index = state.todos.findIndex(todo => todo.id === id ); return immup.set(`todos.${index}.text`, text); }
StoreʹΈࠐΉ reduce(action, payload) { switch (action) { case 'addNewQuery': {
return this .set('selectedQueryId', payload.query.id) .set('editor.line', null) .prepend('queries', payload.query); } //... } }
·ͱΊ • Domain LogicAction Creator͔ΒݺͿΑ͏ ʹͯ͠Έͨ • StoreΛPage୯ҐͰׂͯ͠Έͨ • Stateߋ৽ͷͨΊͷศརϞδϡʔϧ࡞ͬͨ
None