viewmodel-architecture-governance
Installation
SKILL.md
ViewModel Architecture Governance
This skill centralizes all architectural mandates for ViewModels to ensure consistency, testability, and resource efficiency.
1. Passive Initialization Mandate
The ViewModel constructor and init block MUST remain passive. It is strictly forbidden to launch coroutines or start data collection during construction.
Rationale
- Testability: Mocks and test rules must be configured before any work starts. If
initlaunches work, the test cannot control the starting conditions. - Resource Efficiency: Avoid wasting CPU/Battery if the ViewModel is instantiated (e.g., in a backstack) but the UI is not yet visible.
- Predictability: Ensures the UI is observing the state before the first emission occurs, avoiding missed events.
Strategies to stay passive:
A. For Imperative Actions (One-shot loads, manual triggers)
Expose a dedicated function (e.g., onStart() or loadData()) and trigger it from the UI.