Redux - 4Developers

PODRÓŻE W CZASIE Z
ARCHITEKTURĄ REDUX
ELIASZ SAWICKI
‣ Blog: www.eliaszsawicki.com
‣ Twitter: @EliSawic
REDUX
‣ Skąd i po co?
‣ Jak to działa?
‣ Przemyślenia
SKĄD I PO CO?
CZEGO UŻYĆ?
REACT
KOMPONENTY
FLUX
FLUX
Flux is the application architecture that Facebook uses for
building client-side web applications. It complements React's
composable view components by utilizing a unidirectional
data flow. It's more of a pattern rather than a formal
framework, and you can start using Flux immediately without a
lot of new code.
FLUX
‣ application architecture
‣ unidirectional data flow
‣ pattern
‣ without a lot of new code
DAN ABRAMOV
FRUSTRACJA
▸ Frustracja (łac. frustratio - zawód, udaremnienie) – zespół
przykrych emocji związanych z niemożliwością realizacji
potrzeby lub osiągnięcia określonego celu.
▸ np. Gdy kolejny raz odtwarzasz stan aplikacji podczas pracy
nad nową funkcjonalnością
DEV TOOLS
TIME TRAVEL
Redux - 4Developers
RECORDING
Redux - 4Developers
HOT RELOADING
Redux - 4Developers
FLUX
NIE DO KOŃCA
WSPIERAŁ
REDUX
Redux - 4Developers
RESWIFT
DUŻO ZALEŻY OD
PLATFORMY
SKĄD I PO CO?
‣ wyszedł ze świata webowego
‣ inspirowany Fluxem
‣ oparty na chęci szybszej
iteracji
‣ dużo zależy od platformy
‣ podejście
JAK TO DZIAŁA?
WYOBRAŹMY TO SOBIE
URZĄD SKARBOWY
EXCEL
WYSŁAĆ LIST
POPROSIĆ
KSIĘGOWEGO
URZĄD SKARBOWY
ODBIERA
PRZEKAZUJE DO
URZĘDNIKA
URZĘDNIK
AKTUALIZUJE
AKTA
AKTUALIZUJE
AKTA
FIRMY
Redux - 4Developers
DOSTAJEMY
INFORMACJĘ
ZWROTNĄ
AKTUALIZACJA
EXCELA
EXCEL
LIST
URZĄD SKARBOWY
URZĘDNIK
URZĘDNIK
STAN
STAN
REDUX
GŁÓWNE ELEMENTY
‣ State
‣ Actions
‣ Reducers
‣ Store
STATE
Redux - 4Developers
STATE
PROSTY STAN
struct CompanyState {
var isTaxPaidOnTime: Bool
}
STAN APLIKACJI SKŁADA SIĘ Z PODSTANÓW
struct ApplicationState {
var companyState: CompanyState
var loginState: LoginState
var user: User
var navigationState: NavigationState
}
VIEW
STATE
ACTIONS
AKCJA NIOSĄCA DANE
struct ChangeTaxPaymentStatus: Action {
let isPaid: Bool
}
AKCJA OPARTA NA TYPIE
struct IncreaseCounter: Action {}
VIEW
ACTION
STATE
ACTION CREATORS
TWORZENIE AKCJI
func updateAccount() {
getTaxInfo(completion: { tax in
store.dispatch(ChangeTaxPaymentStatus(isPaid: tax.isPaid))
})
}
STORE
ODBIERA LISTY
ZARZĄDZA ZMIANAMI
INFORMUJE O
ZMIANACH
INFORMACJE O ZMIANIE
protocol Store {
func subscribe(subscriber: Subscriber)
}
WYSYŁANIE LISTÓW
protocol Store {
func subscribe(subscriber: Subscriber)
func dispatch(action: Action)
}
TWORZENIE STORE’A
protocol Store {
func subscribe(subscriber: Subscriber)
func dispatch(action: Action)
init(urzędnicy: Urzędnicy, state: State)
}
TWORZENIE STORE’A
protocol Store {
func subscribe(subscriber: Subscriber)
func dispatch(action: Action)
init(reducer: Reducer, state: State)
}
VIEW
ACTION
STORE
STATE
STATE
REDUCER
REDUCER
(Action, State?) -> State
REDUCER APLIKACJI
func appReducer(action: Action, state: AppState?) -> AppState {
return AppState(
companyState: companyReducer(action, user: state?.companyState),
navState: navReducer(action, navState: state?.navState)
)
}
REDUCER PODSTANU
func companyReducer(action: Action, company: CompanyState?) -> CompanyState
{
var resultCompany = company ?? CompanyState()
switch action {
case let action as ChangeTaxPaymentStatus:
resultCompany.isTaxPaidOnTime = action.isPaid
}
return resultCompany
}
REDUCER + FLUXREDUX
VIEW
ACTION
STORE
REDUCER
REDUCER
STATE
STATE
TO NIE WSZYSTKO
STORE APLIKACJI
let mainStore = Store<AppState>(reducer: counterReducer, state: nil)
SUBSCRIBE
class CounterViewController: UIViewController, StoreSubscriber {
override func viewWillAppear(_ animated: Bool) {
mainStore.subscribe(self)
}
override func viewWillDisappear(_ animated: Bool) {
mainStore.unsubscribe(self)
}
}
NEW STATE
class CounterViewController: UIViewController, StoreSubscriber {
func newState(state: AppState) {
...
}
}
DISPATCH ACTION
class CounterViewController: UIViewController, StoreSubscriber {
@IBAction func upButtonTapped(_ sender: UIButton) {
mainStore.dispatch(CounterIncrease())
}
@IBAction func downButtonTapped(_ sender: UIButton) {
mainStore.dispatch(CounterDecrease())
}
}
PROSTE AKCJE
struct CounterIncrease: Action {}
struct CounterDecrease: Action {}
ACTION CREATOR
struct CounterSetValue: Action {
var value: Int
}
func setCounterValue() {
countRepository.getCount { count in
store.dispatch(CounterSetValue(value: count))
}
}
REDUCER
func counterReducer(action: Action, state: AppState?) -> AppState {
var state = state ?? AppState()
switch action {
case _ as CounterIncrease:
state.counter += 1
case _ as CounterDecrease:
state.counter -= 1
case let valueAction as CounterSetValue:
state.counter = valueAction.value
default:
break
}
return state
}
REAKCJA NA ZMIANE
class CounterViewController: UIViewController, StoreSubscriber {
func newState(state: AppState) {
counterLabel.text = "Counter: (state.counter)"
}
}
GŁÓWNE ELEMENTY
‣ State
‣ Actions
‣ Reducers
‣ Store
MOJE
PRZEMYŚLENIA
WARTO?
ZALEŻY
POZNAWAJMY INNE
PODEJŚCIA
UNIDIRECTIONAL
DATA
FLOW
AKCJE NIE POSIADAJĄ
CALLBACKÓW
UNIKAJMY
CYKLI
ZDARZEŃ
ROOT A B
ROOT A B
JEDNO
ŹRÓDŁO
PRAWDY
PRZECHOWYWANIE STANU
class ComponentA {
var state: State?
var componentB: ComponentB
func applyState(state: State) {
self.state = state
componentB.applyState(state)
}
}
class ComponentB {
var state: State?
func applyState(state: State) {
self.state = state
}
}
USTAWIANIE STANU
class ComponentA {
var componentB: ComponentB
func applyState(state: State) {
componentB.applyState(state)
}
}
class ComponentB {
func applyState(state: State) {
}
}
STATE MANAGER
STANDARDY
NIE SĄ
ZŁE
WYKONANIE ZADANIA?
ACTION CREATOR
ZMIANA STANU
REDUCER
GDZIE JEST STAN?
STORE
UŁATWIA PRACĘ
DESIGN
FOR
ITERATION
DEV TOOLS
ŁATWY DOSTĘP
DO EKRANÓW,
NAD KTÓRYMI
PRACUJEMY
PRZYGOTOWANE
ODPOWIEDZI
FAKE REQUEST
WIREMOCK
UNIT TESTY
SNAPSHOT TESTY
IOS
SNAPSHOT
TESTCASE
PRZEMYŚLENIA
‣ unidirectional data flow
‣ jedno źródło prawdy
‣ standardy nie są złe
‣ design for iteration
ZAWSZE
JEST
INNA DROGA
1 of 110

Recommended

From mvc to redux: 停看聽 by
From mvc to redux: 停看聽From mvc to redux: 停看聽
From mvc to redux: 停看聽Jeff Lin
1.2K views37 slides
Reducers+flux=redux by
Reducers+flux=reduxReducers+flux=redux
Reducers+flux=reduxShmulik Chicvashvili
735 views15 slides
Redux with angular 2 - workshop 2016 by
Redux with angular 2 - workshop 2016Redux with angular 2 - workshop 2016
Redux with angular 2 - workshop 2016Nir Kaufman
2.4K views102 slides
Introduction to react and redux by
Introduction to react and reduxIntroduction to react and redux
Introduction to react and reduxCuong Ho
1.5K views26 slides
An Introduction to Redux by
An Introduction to ReduxAn Introduction to Redux
An Introduction to ReduxNexThoughts Technologies
1.2K views24 slides
Reactive.architecture.with.Angular by
Reactive.architecture.with.AngularReactive.architecture.with.Angular
Reactive.architecture.with.AngularEvan Schultz
3.7K views95 slides

More Related Content

Similar to Redux - 4Developers

[@NaukriEngineering] Flux Architecture by
[@NaukriEngineering] Flux Architecture[@NaukriEngineering] Flux Architecture
[@NaukriEngineering] Flux ArchitectureNaukri.com
342 views13 slides
Unidirectional Data Flow Architecture (Redux) in Swift by
Unidirectional Data Flow Architecture (Redux) in SwiftUnidirectional Data Flow Architecture (Redux) in Swift
Unidirectional Data Flow Architecture (Redux) in SwiftSeyhun AKYUREK
842 views11 slides
Introduction to React for Frontend Developers by
Introduction to React for Frontend DevelopersIntroduction to React for Frontend Developers
Introduction to React for Frontend DevelopersSergio Nakamura
17 views27 slides
React Native +Redux + ES6 (Updated) by
React Native +Redux + ES6 (Updated)React Native +Redux + ES6 (Updated)
React Native +Redux + ES6 (Updated)Chiew Carol
697 views31 slides
Redux. From twitter hype to production by
Redux. From twitter hype to productionRedux. From twitter hype to production
Redux. From twitter hype to productionJenya Terpil
450 views51 slides
State manager in Vue.js, from zero to Vuex by
State manager in Vue.js, from zero to VuexState manager in Vue.js, from zero to Vuex
State manager in Vue.js, from zero to VuexCommit University
159 views65 slides

Similar to Redux - 4Developers(20)

[@NaukriEngineering] Flux Architecture by Naukri.com
[@NaukriEngineering] Flux Architecture[@NaukriEngineering] Flux Architecture
[@NaukriEngineering] Flux Architecture
Naukri.com342 views
Unidirectional Data Flow Architecture (Redux) in Swift by Seyhun AKYUREK
Unidirectional Data Flow Architecture (Redux) in SwiftUnidirectional Data Flow Architecture (Redux) in Swift
Unidirectional Data Flow Architecture (Redux) in Swift
Seyhun AKYUREK842 views
Introduction to React for Frontend Developers by Sergio Nakamura
Introduction to React for Frontend DevelopersIntroduction to React for Frontend Developers
Introduction to React for Frontend Developers
Sergio Nakamura17 views
React Native +Redux + ES6 (Updated) by Chiew Carol
React Native +Redux + ES6 (Updated)React Native +Redux + ES6 (Updated)
React Native +Redux + ES6 (Updated)
Chiew Carol697 views
Redux. From twitter hype to production by Jenya Terpil
Redux. From twitter hype to productionRedux. From twitter hype to production
Redux. From twitter hype to production
Jenya Terpil450 views
State manager in Vue.js, from zero to Vuex by Commit University
State manager in Vue.js, from zero to VuexState manager in Vue.js, from zero to Vuex
State manager in Vue.js, from zero to Vuex
Commit University159 views
Introducing Vuex in your project by Denny Biasiolli
Introducing Vuex in your projectIntroducing Vuex in your project
Introducing Vuex in your project
Denny Biasiolli139 views
Enterprise State Management with NGRX/platform by Ilia Idakiev
Enterprise State Management with NGRX/platformEnterprise State Management with NGRX/platform
Enterprise State Management with NGRX/platform
Ilia Idakiev283 views
Introduction to ReactJS and Redux by Boris Dinkevich
Introduction to ReactJS and ReduxIntroduction to ReactJS and Redux
Introduction to ReactJS and Redux
Boris Dinkevich474 views
Introduction to ReactJS by Daine Mawer
Introduction to ReactJSIntroduction to ReactJS
Introduction to ReactJS
Daine Mawer57 views
Reactивная тяга by Vitebsk Miniq
Reactивная тягаReactивная тяга
Reactивная тяга
Vitebsk Miniq231 views
Redux training by dasersoft
Redux trainingRedux training
Redux training
dasersoft237 views
Maintaining sanity in a large redux app by Nitish Kumar
Maintaining sanity in a large redux appMaintaining sanity in a large redux app
Maintaining sanity in a large redux app
Nitish Kumar536 views
Redux. From twitter hype to production by FDConf
Redux. From twitter hype to productionRedux. From twitter hype to production
Redux. From twitter hype to production
FDConf8.8K views
Manage the Flux of your Web Application: Let's Redux by Commit University
Manage the Flux of your Web Application: Let's ReduxManage the Flux of your Web Application: Let's Redux
Manage the Flux of your Web Application: Let's Redux
Commit University1.9K views
Let's discover React and Redux with TypeScript by Mathieu Savy
Let's discover React and Redux with TypeScriptLet's discover React and Redux with TypeScript
Let's discover React and Redux with TypeScript
Mathieu Savy729 views
React js programming concept by Tariqul islam
React js programming conceptReact js programming concept
React js programming concept
Tariqul islam1.4K views
redux and angular - up and running by Nir Kaufman
redux and angular - up and runningredux and angular - up and running
redux and angular - up and running
Nir Kaufman1.8K views

More from Eliasz Sawicki

Eliasz sawickimeetupit by
Eliasz sawickimeetupitEliasz sawickimeetupit
Eliasz sawickimeetupitEliasz Sawicki
110 views20 slides
Developing more in less time by
Developing more in less timeDeveloping more in less time
Developing more in less timeEliasz Sawicki
138 views121 slides
The art-of-developing-more-in-less-time-berlin by
The art-of-developing-more-in-less-time-berlinThe art-of-developing-more-in-less-time-berlin
The art-of-developing-more-in-less-time-berlinEliasz Sawicki
273 views111 slides
Tech fest by
Tech festTech fest
Tech festEliasz Sawicki
289 views143 slides
Introduction to react native by
Introduction to react nativeIntroduction to react native
Introduction to react nativeEliasz Sawicki
481 views78 slides
Doing more in less time - Mobiconf by
Doing more in less time - MobiconfDoing more in less time - Mobiconf
Doing more in less time - MobiconfEliasz Sawicki
390 views107 slides

More from Eliasz Sawicki(14)

Redux - 4Developers