Press makes heavy usage of reactive code through-out the app. It uses RxJava on Android and Reaktive in shared code.
Screens use a reactive MVI design for abstracting testable code. Each screen has one presenter that consumes user interactions in the form of “events”, performs logic with the help of data repositories and emits UI models back that can be rendered by the screen (example).
Here’s an sample from Android:
class HomeView : FrameLayout() {
fun onAttachedToWindow() {
composebutton.setOnClickListener {
presenter.dispatch(NewNoteClicked)
}
presenter.models()
.takeUntil(detachedFromWindow())
.subscribe(::render)
}
private fun render(model: HomeModel) {
...
}
}
class HomePresenter(...) {
fun models(): Observable<HomeModel> {
val models = database.noteQueries.allNotes()
.asObservable(ioScheduler)
.mapToList()
.map { notes ->
HomeModel(notes)
}
return merge(
models,
viewEvents()
.ofType<NewNoteClicked>
.consumeOnNext { navigator.goTo(ComposeScreenKey) }
)
}
}
Take a look at HomePresenter or EditorPresenter to understand them in detail.