Skip to content

Conversation

@CDRussell
Copy link
Member

Description:
No Asana issue for this one, as it's just a code tidy up.

Although I haven't functionally changed anything, this PR reduces the boilerplate needed in each Activity to obtain its ViewModel. We do this by moving the worst of the boilerplate to the parent Activity as a function.

The result now is that in each Activity, obtaining the ViewModel is as simple as

Now 👇

private val viewModel: BookmarksViewModel by bindViewModel()

Before 👇

@Inject	
lateinit var viewModelFactory: ViewModelFactory

private val viewModel: BookmarksViewModel by lazy { 
    private val viewModel: BookmarksViewModel by bindViewModel()
    ViewModelProviders.of(this, viewModelFactory).get(BookmarksViewModel::class.java)	
}

Steps to test this PR:

  1. Just make sure the app is compiled and opens without crashing

Internal references:

Software Engineering Expectations
Technical Design Template

Copy link
Contributor

@brindy brindy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely an improvement.

I strongly dislike the ViewModelFactory though, would much prefer to have a module for view models and inject them directly.

That said, ultimately we'd get rid of Dagger as well. :)

@CDRussell CDRussell merged commit dc26134 into develop Sep 3, 2018
@CDRussell CDRussell deleted the feature/tidier_way_to_obtain_view_models branch September 3, 2018 08:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants