Skip to content
This repository has been archived by the owner on Mar 23, 2023. It is now read-only.

Latest commit

 

History

History
44 lines (36 loc) · 1.65 KB

architecture.md

File metadata and controls

44 lines (36 loc) · 1.65 KB

UI architecture

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.