MVVM-1: Models, Views, and ViewModels should exclusively expose their state instead of state and data separately.


Description

For example, to ensure that Views display upto-date content, it is recommended that ViewModels expose states rather than just events. This can be achieved by bundling together the data that needs to be displayed. In such way, when one of the fields to be displayed changes, a new state is emitted and the View is updated. This entails that each user interaction involves an action in the ViewModel, enabling a clean separation of concerns between MVVM components.

Example

We created a simple MVVM example.

MVVM event diagram

This is our whole application. There is no business logic in the view. All the business logic is moved to the ViewModel When we want to add a new Note we start a new AddNoteActivity. If we submit the form with the Note details, the note is then submitted to the NoteViewModel which then handles the request.

Check this page to view the complete repository.