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
RxPM-library
Search
Dmitriy Gorbunov
November 23, 2017
Programming
0
68
RxPM-library
Reactive implementation of Presentation Model pattern in Android
Dmitriy Gorbunov
November 23, 2017
Tweet
Share
More Decks by Dmitriy Gorbunov
See All by Dmitriy Gorbunov
Intro to Kotlin/Native and Multi-platform Projects
dmdevgo
1
26
RxPM vs MVP vs MVVM
dmdevgo
0
230
Other Decks in Programming
See All in Programming
0→1 フロントエンド開発 Tips🚀 #レバテックMeetup
bengo4com
0
540
360° Signals in Angular: Signal Forms with SignalStore & Resources @ngLondon 01/2026
manfredsteyer
PRO
0
110
インターン生でもAuth0で認証基盤刷新が出来るのか
taku271
0
190
AIフル活用時代だからこそ学んでおきたい働き方の心得
shinoyu
0
130
Oxlint JS plugins
kazupon
1
600
副作用をどこに置くか問題:オブジェクト指向で整理する設計判断ツリー
koxya
1
590
AI巻き込み型コードレビューのススメ
nealle
0
100
MUSUBIXとは
nahisaho
0
130
登壇資料を作る時に意識していること #登壇資料_findy
konifar
3
920
AI Agent Tool のためのバックエンドアーキテクチャを考える #encraft
izumin5210
6
1.8k
AI & Enginnering
codelynx
0
110
CSC307 Lecture 04
javiergs
PRO
0
650
Featured
See All Featured
Ten Tips & Tricks for a 🌱 transition
stuffmc
0
64
Statistics for Hackers
jakevdp
799
230k
Build The Right Thing And Hit Your Dates
maggiecrowley
38
3k
Building a A Zero-Code AI SEO Workflow
portentint
PRO
0
300
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
26
3.3k
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
140
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
0
140
The Anti-SEO Checklist Checklist. Pubcon Cyber Week
ryanjones
0
55
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
210
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
150
The untapped power of vector embeddings
frankvandijk
1
1.6k
Design in an AI World
tapps
0
140
Transcript
RxPM — реактивная реализация паттерна Presentation Model Дмитрий Горбунов Senior
Android Developer
Why Use RxPM?
RxPM
val inProgress = State<Boolean>(initialValue = false) // Изменяем значение в
PresentationModel inProgress.consumer.accept(true) // Подписываемся на изменения во View pm.inProgress.observable.bindTo(progressBar.visibility()) RxPM - State 4
val buttonClicks = Action<Unit>() // Слушаем клики в PresentationModel buttonClicks.observable
.subscribe { // handle click } .untilDestroy() // Привязываемся во View button.clicks().bindTo(pm.buttonClicks.consumer) RxPM - Action 5
val errorMessage = Command<String>(bufferSize = 1) // Посылаем сообщение из
PresentationModel errorMessage.consumer.accept(message) // Слушаем команды во View pm.errorMessage.observable.bindTo { // show alert dialog } RxPM - Command 6
RxPM - Command 7
class DataPresentationModel(private val dataModel: DataModel) : PresentationModel() { val data
= State<List<Item>>(emptyList()) val inProgress = State(false) val errorMessage = Command<String>() val refreshAction = Action<Unit>() // ... } RxPM - PresentationModel 8
class DataPresentationModel(private val dataModel: DataModel) : PresentationModel() { val data
= State<List<Item>>(emptyList()) val inProgress = State(false) val errorMessage = Command<String>() val refreshAction = Action<Unit>() override fun onCreate() { super.onCreate() refreshAction.observable .skipWhileInProgress(inProgress.observable) .flatMapSingle { dataModel.loadData() .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .bindProgress(inProgress.consumer) .doOnError { errorMessage.consumer.accept("Loading data error") } } .retry() .subscribe(data.consumer) .untilDestroy() // обновляем данные при входе на экран refreshAction.consumer.accept(Unit) } } RxPM - PresentationModel 9
class DataFragment : PmSupportFragment<DataPresentationModel>() { override fun providePresentationModel() = DataPresentationModel(DataModel())
override fun onBindPresentationModel(pm: DataPresentationModel) { pm.inProgress.observable.bindTo(swipeRefreshLayout.refreshing()) pm.data.observable.bindTo { // adapter.setItems(it) } pm.errorMessage.observable.bindTo { // show alert dialog } swipeRefreshLayout.refreshes().bindTo(pm.refreshAction.consumer) } } RxPM - PmView 10
Two-way Data Binding 11
Two-way Data Binding 12
Two-way Data Binding 13
Two-way Data Binding 14
Two-way Data Binding 15
Two-way Data Binding 16
Two-way Data Binding 17
RxPM - Controls 18 // Объявляем в PresentationModel val name
= inputControl( formatter = { it.take(50).toUpperCase() } ) val checked = checkControl(initialChecked = false) // Привязываем виджеты во View pm.name bindTo editText pm.checked bindTo checkBox
Спасибо за внимание! /** * @author Dmitriy Gorbunov (dmdev) *
@author Vasili Chyrvon (Jeevuz) */ Telegram : https://t.me/Rx_PM GitHub : https://github.com/dmdevgo/RxPM Habrahabr : https://habrahabr.ru/company/mobileup/blog/326962/ https://habrahabr.ru/company/mobileup/blog/342850/ Дмитрий Горбунов:
[email protected]