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
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
390
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
210
Elm
sporto
1
300
Practically Immutable
sporto
0
220
Webpack and React
sporto
4
420
Rails with Webpack
sporto
1
260
Lesson learnt building Single Page Application
sporto
0
160
Grunt
sporto
1
230
Safe Testing in Ruby
sporto
1
160
Go - A great language for building web applications
sporto
1
370
Other Decks in Technology
See All in Technology
2拠点SRE活動始めてみた | sogaoh's LT @ ホンマでっかSRE勉強会 #3
sogaoh
PRO
0
240
「いつか使う」の「いつか」は来ない 〜AI駆動開発における「作らない」判断について〜
ikki0006
0
110
FinOpsを導入してマルチプロダクトのコスト最適化を実現する
kworkdev
PRO
0
130
詳解 never 型 - ボトム型の性質を深掘り
nealle
0
150
kintoneで在庫管理システムを作るときの要件定義・設計ポイント
kai0707
0
230
推論基盤と Scale-Up Interconnect の現状と制約から俯瞰する技術動向
markunet
2
810
AWS構成から考えるWebセキュリティ ― WordPressの構築経験から考える公開範囲と更新運用【JAWS FESTA 2026 in AKITA】
cscengineer
PRO
1
200
Building Audio Plugin Ecosystem for Android in 2026
atsushieno
2
150
TSKaigi Sendai 2026 - tsgo時代のTypeScript Playgroundはどう動くか
teamlab
PRO
0
100
デザインレビューは自動化できるのか?─ Flutter × Figma で UI 品質保証を考える
techiro
2
790
AI時代の組織作り:チーム開発から「個人×AI」への移行と、持続可能な「開発資本」の築き方
ham0215
1
110
令和の今、あらためて IAM を考える。アクセスキーを「無くせない現実」との向き合い方
kazzpapa3
0
190
Featured
See All Featured
The Curse of the Amulet
leimatthew05
3
17k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
123
22k
Testing 201, or: Great Expectations
jmmastey
46
8.4k
Code Reviewing Like a Champion
maltzj
529
40k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.6k
SERP Conf. Vienna - Web Accessibility: Optimizing for Inclusivity and SEO
sarafernandez
2
1.6k
Chasing Engaging Ingredients in Design
codingconduct
0
390
HDC tutorial
michielstock
2
1k
Gemini Prompt Engineering: Practical Techniques for Tangible AI Outcomes
mfonobong
2
630
B2B Lead Gen: Tactics, Traps & Triumph
marketingsoph
1
300
Scaling GitHub
holman
464
140k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
23k
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