skydoves / pokedex-compose

🗡️ Pokedex Compose demonstrates modern Android development with Jetpack Compose, Hilt, Coroutines, Flow, Jetpack (Room, ViewModel), and Material Design based on MVVM architecture.
Apache License 2.0
683 stars 112 forks source link

Refactor - Removal of ViewModel instances down to other composables #1

Closed hemantj99 closed 5 months ago

hemantj99 commented 5 months ago

🎯 Goal

This pull request aims to refactor the code by addressing to not to pass a ViewModel instance as a parameter. The fix involves adhering to best practices outlined in the Architecture state holders documentation, which advises against passing ViewModel instances to other composables. Instead, we use a lambda expression to invoke the required method, ensuring cleaner and more maintainable code.

By making this change, we enhance code readability, adhere to recommended architecture patterns, and ensure better maintainability of the project in the long run.

🛠 Implementation details

By hoisting the fetchNextPokemonList function call to the parent composable (also HomeContentPreview()), we adhere to the principle of separating concerns and maintain a clear distinction between UI logic and business logic. This makes the codebase more modular, easier to understand, and less prone to errors.

✍️ Explain examples

Explain examples with code for this updates.

Preparing a pull request for review

Ensure your change is properly formatted by running:

$ ./gradlew spotlessApply

Please correct any failures before requesting a review.