Skip to content

Release 0.7.4 (19)

Compare
Choose a tag to compare
@chRyNaN chRyNaN released this 15 May 18:01
· 33 commits to master since this release
  • Renamed ViewModel to BaseViewModel and made its constructor internal
  • Renamed BasePresenter to ViewModel
  • Renamed PresenterFactory to ViewModelFactory
  • Library now uses more of a "ViewModel" approach to the communication channel between the View and the other design pattern components, instead of the previous "Presenter" approach. This removes a cyclic dependence between the View and the Presenter/ViewModel component.
    • Previously, the BasePresenter had a reference to the View, and the View had a reference to the Presenter. This was needed so that the Presenter could call the View.render function with the new derived State, and so the View could emit intents to the Presenter. This was later abstracted, by having the BasePresenter only take a Flow<Intent> instead of a View, so that there would be no direct reference to the View. These approaches required a PresenterFactory to simplify the creation of a Presenter, and inject the View it was bound to.
    • Now, only the View has a reference to the ViewModel (previously BasePresenter). The View emits intents by calling the ViewModel.intent function. And the View subscribes to State changes via the ViewModel.renderStates property. This way there is no cyclic dependency requirement between the two components.
  • Created View.intent extension function for convenience that just delegates to the ViewModel.intent function.

New usage of the library would look like the following:

class HomeLayout : Layout<HomeIntent, HomeState, HomeChange>() {
 
      override val viewModel = ViewModel<I, S, C>(
              perform = { intent, state -> ... },
              reduce = { state, change -> ... })
 
      @Composable
      override fun Content() {
          val state by stateChanges()
 
          Text("State = $state")
       }

       override fun onBind() {
           intent(to HomeIntent.Load())
       }
}

Full Changelog: 0.7.3...0.7.4