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
Redux: Flux Reduced
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
sporto
August 31, 2015
Technology
380
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Redux: Flux Reduced
sporto
August 31, 2015
More Decks by sporto
See All by sporto
React inside Elm
sporto
2
200
Elm
sporto
1
290
Practically Immutable
sporto
0
210
Webpack and React
sporto
4
410
Rails with Webpack
sporto
1
250
Lesson learnt building Single Page Application
sporto
0
150
Grunt
sporto
1
210
Safe Testing in Ruby
sporto
1
150
Go - A great language for building web applications
sporto
1
360
Other Decks in Technology
See All in Technology
『自分で判断できるか』を基準に、プロダクトのハンズオン研修でAI利用の線を引いてみた / Where We Drew the Line on AI in Hands-on Training
honyanya
0
290
Data Hubグループ 紹介資料
sansan33
PRO
0
3.2k
Kiro WebとCloud Sessions
nagisa53
2
210
[ホンマでっか SRE] あなたはなぜ SRE に?
_awache
0
280
Windows の互換機能 - 古いプログラムはなぜ動作できるのか
murachiakira
PRO
0
120
MCPを待つな、パスキーを拡げよう(OAuth/OIDC Numa (Immersion) Workshop 2026)
oidfj
PRO
0
320
Digitization部 紹介資料
sansan33
PRO
2
7.7k
暗号化?某ファイルストレージはどうなるの!? 3rd Partyとうまく付き合う秘密度ラベル設計
kasada
0
210
Contract One Engineering Unit 紹介資料
sansan33
PRO
0
20k
1000⼈規模のClaude Enterprise運⽤を「Oktaのグループ」と「Slack」に集約する
sansantech
PRO
0
440
AI駆動開発を組織で促すために
lycorptech_jp
PRO
6
7.9k
サーバー常駐型の 簡易障害調査AI エージェントを作ってみた話
masayoshi
0
230
Featured
See All Featured
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
360
30k
Tell your own story through comics
letsgokoyo
1
1k
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.4k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
201
75k
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
390
Optimizing for Happiness
mojombo
378
71k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
Imperfection Machines: The Place of Print at Facebook
scottboms
270
14k
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
0
490
AI Search: Where Are We & What Can We Do About It?
aleyda
0
7.8k
Deep Space Network (abreviated)
tonyrice
0
270
Transcript
Redux flux reduced @sebasporto
Flux • Made popular by Facebook for building React applications
• Old pattern (CQRS) with different naming for everything
Flux View Dispatcher Action (Event) Users Store Posts Store Action
(Event) Change Grab New state
Flux Orders Stats 1 $400 2 $100 ... Countries 1
Aus 2 Fra ... Aus $500 Fra $600 ... Today $ 100 ... • Makes state consistency across views much easier
Component Singleton Flux Store Dispatcher Message Get state
Server side rendering • Original flux, everything is a singleton
• Make SSR much harder • Each request needs its own universe
Server side rendering • Flux implementations without singletons started showing
up • Alt, Fluxible, Flummox, etc
Request arrives Render Tree Pass everything Response Server side rendering
Create users store Create orders store Create dispatcher
Problem • Too many things to instantiate and pass around
What if we only have one state object? Users store
Orders store Countries store Reduced to { users orders countries }
Redux only has one big state tree Less things to
create and pass around ORDERS COUNTRIES USERS STATE
Now we can just move the dispatcher inside the state
obj Dispatcher State Reduced to { dispatch, state: { users orders ... } }
Redux is only one object 04 State Dispatch Redux store
Render Tree Pass store Response Server side rendering Create redux
instance Request
Traditional flux case 'USERS_FETCH_SUCCESS': users = action.users state.push(users) break •
We manage the state on the stores
What if we just describe the transformations?
• Inspired by ELM updaters update action model = case
action of Increment -> model + 1 Decrement -> model - 1
function reducer(state, action) { switch(action.type) { case 'USERS_FETCH_SUCCESS': users =
action.users return state.merge(users) ... } } Reducers in Redux
Reducers in Redux • The expect you to return a
copy of the state, not mutate it • This is great for debugging • Seamless-immutable is great for this
The state is managed by Redux, you only describe the
transformations
redux Redux View dispatch Action (Event) state Change Grab New
state Reducers
Components of Redux
{ type: 'USERS_FETCH_SUCCESS' users: [...] } Action
function fetchSuccess(users) return { type: 'USERS_FETCH_SUCCESS' users: [...] } }
Action creator
const action = fetchSuccess(users) store.dispatch(action) Dispatch
function reducer(state, action) { switch(action.type) { case 'USERS_FETCH_SUCCESS': users =
action.users return state.merge(users) } } Reducer
Interacting with the outside world? e.g. ajax
redux View dispatch Async Action state Change Reducers Async Action
creators Async action Request Response Action Run async action
function fetch() return function(dispatch) { doSomeAjax(...) .then(function(response) { const successAction(response.data)
dispatch(successAction) } } } Async Action creators
Middleware Middleware redux View dispatch Action Action
Middleware • Logging • Stoping unnecessary request • Async actions
• Dev tools 04 03 02 01
redux View dispatch Action state Change Reducers Redux is really
simple
Not React specific anymore • Just an event and state
management library • Can be used with other things e.g. ng-redux
Interacting directly with the store import { createStore } from
'redux' const store = createStore(reducers) store.getState() store.subscribe(listener) store.dispatch(action)
With React import { createStore } from 'redux' import Provider
from 'react-redux' const store = createStore({...}) React.render(( <Provider store={store}> {() => <App />} </Provider> ), mountNode);
Other cool stuff
Hot reloading • Works quite well most of the time
• Will keep state intact
Dev tools
Time travel
Redux-crud Building CRUD apps? • Standard actions creators and reducers
for CRUD apps • https://github.com/Versent/redux-crud
Thanks