Интересные размышления на тему: "В какой момент дергать UseCase (или репозиторий) в ViewModel". Автор предлагает несколько решений и описывает плюсы и минусы.
#android #mvvm #viewmodel
https://proandroiddev.com/when-to-load-data-in-viewmodels-ad9616940da7
#android #mvvm #viewmodel
https://proandroiddev.com/when-to-load-data-in-viewmodels-ad9616940da7
Medium
When to load data in ViewModels
Recently I had a surprisingly long discussion on an ostensibly easy question. Where in our code should we actually trigger the loading of…
Статья о том как под капотом реализовано сохранение ViewModel живым при повороте экрана.
#android #viewmodel
https://blog.mindorks.com/android-viewmodels-under-the-hood
#android #viewmodel
https://blog.mindorks.com/android-viewmodels-under-the-hood
Mindorks
Android ViewModels: Under the hood
In this article, we are going to discuss the internals of ViewModel which is a part of Android Architecture Components. We will first briefly discuss the usages of ViewModel in Android and then we will go in detail about how ViewModel actually works and…
Подробный разбор механизма "живучести" ViewModel
#android #jetpack #viewmodel
https://bowser-f.medium.com/how-viewmodel-works-under-the-hood-52a4f1ff64cf
#android #jetpack #viewmodel
https://bowser-f.medium.com/how-viewmodel-works-under-the-hood-52a4f1ff64cf
Medium
How ViewModel works under the hood
Learn how a ViewModel survives to a configuration change
Краткий обзор фабрик, которые дают нам возможность повлиять на создание основных Android сущностей
- AppComponentFactory for customising the instantiation of application components
- LayoutInflater.Factory2 and View for customising view inflation
- FragmentFactory for customising fragment creation
- ViewModelProvider.Factory with CreationExtras for simplifying ViewModel creation
- WorkerFactory for customising Worker creation in WorkManager
#android #activity #fragment #viewmodel #di
https://marcellogalhardo.dev/posts/injection-points/
- AppComponentFactory for customising the instantiation of application components
- LayoutInflater.Factory2 and View for customising view inflation
- FragmentFactory for customising fragment creation
- ViewModelProvider.Factory with CreationExtras for simplifying ViewModel creation
- WorkerFactory for customising Worker creation in WorkManager
#android #activity #fragment #viewmodel #di
https://marcellogalhardo.dev/posts/injection-points/
В Hilt появилась возможность использовать Assisted Injection для ViewModel, чтобы передавать свои объекты в конструктор модели.
#android #dagger #hilt #viewmodel
https://medium.com/@alexander.michaud/hiltviewmodel-assisted-injection-with-compose-a800723165bf
#android #dagger #hilt #viewmodel
https://medium.com/@alexander.michaud/hiltviewmodel-assisted-injection-with-compose-a800723165bf
Статья о технической реализации UI событий в ViewModel
#android #viewmodel #architecture #event
https://proandroiddev.com/viewmodel-events-as-state-are-an-antipattern-35ff4fbc6fb6 (Оригинал)
https://shorturl.at/dghip (Перевод)
#android #viewmodel #architecture #event
https://proandroiddev.com/viewmodel-events-as-state-are-an-antipattern-35ff4fbc6fb6 (Оригинал)
https://shorturl.at/dghip (Перевод)
Medium
ViewModel: Events as State are an Antipattern
In this article Nikita explores how a popular notion about expressing events as states may be a misleading one.
В третьей части серии статей о ViewModel Best Practices обсуждают следующие пункты:
- Try not to import Android dependencies in the ViewModels:
- Lazily inject dependencies in the constructor.
#android #viewmodel
https://proandroiddev.com/mastering-android-viewmodels-essential-dos-and-donts-part-3-%EF%B8%8F3%EF%B8%8F%E2%83%A3-1833ce3ddd2b
- Try not to import Android dependencies in the ViewModels:
- Lazily inject dependencies in the constructor.
#android #viewmodel
https://proandroiddev.com/mastering-android-viewmodels-essential-dos-and-donts-part-3-%EF%B8%8F3%EF%B8%8F%E2%83%A3-1833ce3ddd2b
Вторая часть статьи про начальную загрузку данных в ViewModel. Отвечает на самые распространенные вопросы, возникшие после первой части.
1. What if you want to pass arguments when loading initial data
2. What if you want to refresh?
3. Why are ViewModel.init side-effects potentially problematic?
4. How to prevent re-emitting flow from WhileSubscribed(5_000)
#android #viewmodel #architecture #bestpractice
https://proandroiddev.com/loading-initial-data-part-2-clear-all-your-doubts-0f621bfd06a0
1. What if you want to pass arguments when loading initial data
2. What if you want to refresh?
3. Why are ViewModel.init side-effects potentially problematic?
4. How to prevent re-emitting flow from WhileSubscribed(5_000)
#android #viewmodel #architecture #bestpractice
https://proandroiddev.com/loading-initial-data-part-2-clear-all-your-doubts-0f621bfd06a0
Medium
Loading Initial Data on Android Part 2: Clear All Your Doubts
When a user enters a screen, the default data should be fetched by triggering the business logic, whether from the network or local…
Dos and Don’ts для ViewModel, часть 5:
- Avoid hardcoding Coroutine Dispatchers.
- Unit test your ViewModels.
- Avoid exposing suspended functions.
#kotlin #android #viewmodel #bestpractise
https://proandroiddev.com/mastering-android-viewmodels-essential-dos-and-donts-part-5-%EF%B8%8F5%EF%B8%8F%E2%83%A3-14d04ec2426a
- Avoid hardcoding Coroutine Dispatchers.
- Unit test your ViewModels.
- Avoid exposing suspended functions.
#kotlin #android #viewmodel #bestpractise
https://proandroiddev.com/mastering-android-viewmodels-essential-dos-and-donts-part-5-%EF%B8%8F5%EF%B8%8F%E2%83%A3-14d04ec2426a
Medium
Mastering Android ViewModels: Essential Dos and Don’ts Part 5 🛠️5️⃣
keep these in mind for better code quality when doing ViewModels!
Автор попытался создать ViewModel со временем жизни Composable функции. Штука, может и ненужная, но интересная, чтобы лучше понимать и Compose и ViewModel.
#android #compose #viewmodel #lifecycle
https://proandroiddev.com/composable-scoped-viewmodel-an-interesting-experiment-b982b86d84cd
#android #compose #viewmodel #lifecycle
https://proandroiddev.com/composable-scoped-viewmodel-an-interesting-experiment-b982b86d84cd
Medium
Composable-scoped ViewModel: An interesting experiment
Scope any ViewModel to the composition of the Composable it is in, while surviving configuration changes, by using the power of Lifecycle.