redux + (rxkotlin | rxswift) == awesome native mobile apps...o external data sources o apis, content...
Post on 03-Jun-2020
8 Views
Preview:
TRANSCRIPT
Redux + (RxKotlin | RxSwift) == Awesome Native Mobile Apps Mohanraj K.M, Sr. Engineering Manager, Amadeus Labs
https://medium.com/@kmmraj
Understand the need & Take Away
Problem
Incremental Changes
Vs
Disruptive Changes
Let’s Understand – Why we need?
o Adding completely new information to an existing screen
o New screen in existing flow
o How do we react?
App State
o Altering app state
o Rippling changes
How are we updating App State?
o No consistency
How are we updating App State?
o Many sources of truth
How are we updating App State?
o Multiple communication paths
Is there any better way?
1. Single source of truth for App state
o App State
o Sub states - Domains & Screens
2. State is read only
o Consistent mechanism
o Centralized function
o Explicit object describing what happened
fun somefunction(action: Action, oldState: AppState?) : AppState •
13
3. Pure function changes the state
fun reducer(action: Action, oldState: AppState?) : AppState _
What about unit testing such mechanism?
14
Store
_
15
Story so far
_
16
React to State Changes
o UI Components getting updates
o Subscribe
17
Unidirectional
18
Redux Libs
o ReSwift
o Reductor or ReKotlin
Code Snippets – Activity / ViewController
o External Data Sources
o APIs, Content providers, local databases like SQLite, CoreData.
o Who in the unidirectional flow can take care of this responsibility?
23
Where I will get the Data?
Middleware
Code snippets
LoginActivity
mainStore
middleware
appReducer
AppState
API
authenicationReducer
authenicationState
isFetching=true
LoginStartedAction
newState
showProgressBar
LoginAction
START
FINISH
Unidirectional - contd
LoginActivity
mainStore
middleware
appReducer
AppState
API
authenicationReducer
LoginAction
START FINISH
API
Call backs Hell … What Next ?
3 Steps
o Create a stream
o Transform the stream
o Subscribe to the stream
Libraries - Choices
o iOS – or
o Android – RxKotlin or Kotlin Coroutines (experimental)
mainStore
LoginActivity
mainStore
middleware
appReducer
AppState
API
authenicationReducer
LoginAction
START FINISH
API
Another Action
Who will tie up the Observable and the Subscriber?
https://medium.com/@kmmraj
Unit Testing Middleware — Observables — Stream creators
https://medium.com/@kmmraj
Unit Testing Middleware — Subscribers — Stream consumers
https://medium.com/@kmmraj
Summary
https://medium.com/@kmmraj
o Separation of Concerns o Reactive X o Redux
o Testability o Flow less nature of screens o Learning curve
Thank you
https://medium.com/@kmmraj
|
Choices of ReactiveX libs
ReactiveCocoa ReSwift
By Github By ReactiveX
Cold & Hot Signal Only one sequence
Errors are strongly typed Generic type baked in, not possible to catch when specific error type
RxKotlin Corountines
top related