- Add 60 new agents across all 10 categories (75 -> 135) - Add 95 new plugins with command files (25 -> 120) - Update all agents to use model: opus - Update README with complete plugin/agent tables - Update marketplace.json with all 120 plugins
1.3 KiB
1.3 KiB
/add-viewmodel - Add ViewModel
Create an Android ViewModel with proper state management and data flow.
Steps
- Ask the user for the ViewModel name and the data it manages
- Create the ViewModel class extending androidx.lifecycle.ViewModel
- Define sealed interfaces for UI state, UI events, and side effects
- Initialize StateFlow for the UI state with a sensible default
- Add repository or use case dependencies via constructor injection (Hilt)
- Implement event handling: map user actions to state changes
- Add error handling with proper error state propagation
- Implement data loading with coroutines in viewModelScope
- Add retry logic for failed network requests
- Create unit tests with fake repositories and TestDispatcher
- Add Hilt @Inject annotation and module binding
- Document the state machine: states, events, and transitions
Rules
- Never expose mutable state directly; use private MutableStateFlow with public StateFlow
- Use sealed interfaces for UI state to ensure exhaustive handling
- Handle all coroutine exceptions with CoroutineExceptionHandler
- Cancel ongoing operations in onCleared if needed
- Use SavedStateHandle for surviving process death
- Keep ViewModels thin; delegate business logic to use cases
- Do not reference Activity, Context, or View classes in ViewModels