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
try Undux but...
Search
tt
September 19, 2018
Programming
0
230
try Undux but...
I tryed Undux of state management but Redux is better that.
tt
September 19, 2018
Tweet
Share
More Decks by tt
See All by tt
戦略的なフロントエンドテストを実施するために
tatsushitoji
0
50
そろそろGraphQLの話をしよう
tatsushitoji
1
250
Our favorite Dependency updates has been deprived
tatsushitoji
2
420
Other Decks in Programming
See All in Programming
はてなにおける CSS Modules、及び CSS Modules に足りないもの / CSS Modules in Hatena, and CSS Modules missing parts
mizdra
7
1k
dbtのドメイン分割による データ基盤の改善とDigdagとの連携
sakama
0
480
効率化に挑戦してみたらモバイル開発が少し快適になった話
ryunakayama
0
140
Implementing Design Systems in Swift
seyfoyun
2
500
Compose-View Interop in Practice (mDevCamp 2024)
stewemetal
0
170
Amazon SQSコンシューマー疎結合への旅 - 出張! #DevelopersIO IT技術ブログの中の人が語る勉強会 #3
quiver
0
350
大規模Reactアプリのリアーキテクチャ~8万行のTanStack Query移行の軌跡~
kj455
4
1k
Going beyond Apache Parquet's default settings
xhochy
0
140
Next.js App Router
quramy
12
2.1k
Webアプリをできるだけコードを手書きしないで作ってみる
tomokusaba
2
190
見た目から始める生産性向上
ikumatadokoro
10
1.5k
Domain-Driven Transformation
hschwentner
2
1.5k
Featured
See All Featured
Automating Front-end Workflow
addyosmani
1357
200k
RailsConf 2023
tenderlove
9
570
Keith and Marios Guide to Fast Websites
keithpitt
408
22k
The Language of Interfaces
destraynor
151
23k
The Illustrated Children's Guide to Kubernetes
chrisshort
32
47k
4 Signs Your Business is Dying
shpigford
176
21k
Web development in the modern age
philhawksworth
203
10k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
352
28k
Thoughts on Productivity
jonyablonski
60
3.9k
Teambox: Starting and Learning
jrom
128
8.4k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
22
1.6k
Fireside Chat
paigeccino
22
2.6k
Transcript
ReduxʹർΕͨͷͰ UnduxΛૉৼΓͯ͠Έͨ Osaka Mix Leap Study #23 React Nativeษڧձ @tatsushitoji
Who am I ? • @tatsushitoji • σβΠϯࣄॴɺήʔϜձࣾɺweb੍࡞ձ ࣾɺۙͰιʔγϟϧϩάΠϯͳͲΛఏڙ ͢ΔࣄۀձࣾΛܦͯɺݱࡏɺwebࣄۀҎ֎
ͷۀछΛபͱͨ͠ձࣾͰwebࣄۀͷ্ཱͪ͛ Λߦ͍ͬͯ·͢
Dead simple state management for React
storeΛ࡞ import { createConnectedStore } from 'undux' import { initialCounterState
} from './modules/counter' export const store = createConnectedStore({ ...initialCounterState, }) import { createStore, combineReducers } from 'redux' import { counterReducer } from ‘./modules/counter' export const store = createStore( combineReducers({ counter: counterReducer, }), ) 6OEVY 3FEVY
ContainerͰϥοϓ͢Δ import Store from './store' import { Counter } from
'./components/counter' import registerServiceWorker from './registerServiceWorker' ReactDOM.render( <Store.Container> <Counter /> </Store.Container>, document.getElementById('root') import { store } from './store' import { Container as Counter } from './containers/counter' ReactDOM.render( <Provider store={store}> <Counter /> </Provider>, document.getElementById('root') ) 6OEVY 3FEVY
connect͢Δ import * as React from 'react' import { withStore
} from '../../store' export const Counter = withStore(({ store }) => ( <> … </> )) import { connect } from 'react-redux' import { Counter } from '../../components/counter' export const Container = connect(state => state)(Counter) 6OEVY 3FEVY
Dead Simple ! import * as React from 'react' import
{ withStore } from '../../store' export const Counter = withStore(({ store }) => ( <div> <p>count: {store.get('countValue')}</p> <button onClick={() => store.set('countValue')(store.get('countValue') + 1)}>Increment</button> <button onClick={() => store.set('countValue')(store.get('countValue') - 1)}>Decrement</button> <button onClick={() => store.set('countValue')(0)}>Reset</button> </div> ))
͔ͨ͠ʹγϯϓϧ͕ͩεέʔϧ ͢Δ…ʁ • storeΛ·Δ͝ͱίϯϙʔωϯτʹͭͬ͜Ήͱ ͍͏உؾ͋;ΕΔେͳઃܭ • view ଆ(presentational Component)ʹ͕ ৭ʑͱͬͯ͘Δ
ͬͯΈͨ • storeUpdaterͷ • Store Λඞཁͳ͚ͩϚοϐϯά
ຐվ… export const Counter = compose( withStore, withHandlers({ onIncrement: ({
store }) => () => store.set('countValue')(store.get('countValue') + 1), onDecrement: ({ store }) => () => store.set('countValue')(store.get('countValue') - 1), onReset: ({ store }) => () => store.set('countValue')(0), }), mapProps(({ store, onIncrement, onReset, onDecrement }) => ({ onIncrement, onDecrement, onReset, countValue: store.get('countValue'), })), )(Component)
• mapProps Ͱ react-redux ͷ mapStateToProps ʹ͍ۙ͜ͱΛ͍ͬͯΔ • WithHandlers Ͱ
react-redux ͷ mapDispatchToProps ʹ͍ۙ͜ͱΛ͍ͬͯΔ • ܕͭΒ͍ • Redux ͍͍͑ͷͰ…ʁ
ReduxʹർΕͨͷͰ UnduxΛૉৼΓͯ͠Έͨ…
݁Ռɺ ෳਓ։ൃɺ·ͨ͋ΔఔنҎ্ ͕ఆ͞ΕΔΞϓϦέʔγϣϯͷঢ়ଶ ཧʹ͓͍ͯ Redux ͷ store ͷ mutaion ͷઃܭͱ
react-redux ͷ connect ڞ௨ೝࣝͱ͍ͯ࣋ͪ͢͠ ͠ɺducks ͳσΟϨΫτϦߏʹ͢Ε ϑΝΠϧҠಈͷΦʔόʔϔου͑ ΒΕΔ͠… ͦͦɺReduxʹർΕͯͳͲ͍ͳ͍
ϦϙδτϦ • https://github.com/tatsushitoji/cra-redux • https://github.com/tatsushitoji/cra-undux ※ feat/optimize-connect ϒϥϯνͰ͋Δఔ·Ͱͷ࠷దԽΛ͍ͬͯ·͢
͝ਗ਼ௌ ͋Γ͕ͱ͏͍͟͝·ͨ͠