導入反應式編程的⼼心路路歷程
Android Developer - PicCollage
Prada
Why reactive programing matter, and how PicCollage adaptive it.
Why Reactive
Programming matters?
https://www.youtube.com/watch?v=v68ppDlvHqs
1. Deal with Threading right is matters
2. Architecture also need to be reactive.
Old World
You Code shouldn’t like this
Our World is shifting
Blocking -> Non-Blocking
Computer -> User
Developer suffering
from Threading
I was join PicCollage in 2013
we have over 30 Customized AsyncTask Classes
Deferred-Promise Pattern
is Popular
we tried jDeferred and Bolts-Framework
https://github.com/jdeferred/jdeferred
https://github.com/BoltsFramework
We went to Android SF
Meetup in 2016
https://tech.pic-collage.com/android-meetup-in-san-fransisco-e1e8dde1554c
Implement thread in
RxJava
https://tech.pic-collage.com/android-meetup-in-san-fransisco-e1e8dde1554c
https://youtu.be/XLH2v9deew0?t=4m51s
Asynchronous Ideas
1. Explicit execution
2. Easy thread management
3. Easily transformable
4. As few side effect as possible
5. Cancelation
Architecture also need
to be reactive
Trending : Make Model/
State be reactive
Google try to move to
MVVM pattern
https://developer.android.com/topic/libraries/data-binding/index.html
Android Architecture
Component
https://developer.android.com/topic/libraries/architecture/index.html
Trending : isolated Android
framework dependency
Android Dev Hates
Activity/Fragment LifeCycle
Your Code might looks like
MyActivity.java
Takes View’s Input
Update Views
Control Logic
Data/Model
MVC⼀一家親
Your Code might looks like
MyActivity.java
Takes View’s Input
Update Views
Control Logic
VC⼀一家親
MyContentProvider.java
Data/Model
Model-View-Presenter
MyActivity.java
Takes View’s Input
Update Views
MyContentProvider.java
Data
MyPresenter.java
Control Logic
IView.java IPresenter.java
Trending : Controller
need to be reactive
You might want your
controller looks like
In the end, Your code will be
https://www.youtube.com/watch?v=0IKHxjkgop4
Adoption steps from
PicCollage
1. UI interaction
2. Threading mechanism
3. Make Data Layer API be reactive
4. Make Controller be reactive
UI interaction
https://github.com/JakeWharton/RxBinding
Threading mechanism
Before
After
Data Layer API be reactive
Note : some case you need to use Subject to achieve this goal
https://github.com/ReactiveX/RxJava/wiki/Subject
Controller be reactive
Take away
1. Learn from web developers(Flux, Redux, MVI)
2. Review your threading code
3. Reactive Programming has high learning curve
4. Follow our adoption steps
Thanks, Question?
Reference
Intro to RxJava/ Christina Lee
https://www.youtube.com/watch?v=XLH2v9deew0
Dynamics of change: why reactivity matters/ Andre Staltz
https://www.youtube.com/watch?v=v68ppDlvHqs
Managing State with RxJava/ Jake Wharton
https://www.youtube.com/watch?v=0IKHxjkgop4

Why reactive programing matter, and how PicCollage adaptive it.