Use Delegated ViewModels for KMP compatibility
masterFor projects requiring Kotlin Multiplatform (KMP) compatibility, use the Delegated ViewModels approach. Instead of subclassing ViewModel to implement a Container, you use ContainerViewModel which delegates to a Store.
Key characteristics:
- Robustness: More multiplatform-friendly as it avoids subclassing Android ViewModels directly for logic.
- Complexity: Slightly more boilerplate than the direct approach.
- DI Requirement: Requires injecting your
Containerinto aStoreViewModel, and then injecting thatStoreViewModelinto your Android components. Implementation details depend on your Dependency Injection (DI) framework.