Skip to content

Migrate from ViewModels to Decompose architecture#34

Open
AlexGladkov wants to merge 4 commits into
mainfrom
feature/add-decompose-b998b96f
Open

Migrate from ViewModels to Decompose architecture#34
AlexGladkov wants to merge 4 commits into
mainfrom
feature/add-decompose-b998b96f

Conversation

@AlexGladkov

Copy link
Copy Markdown
Owner

Summary

This PR migrates the JetHabit application from a ViewModel-based architecture to Decompose, a Kotlin Multiplatform library for building reactive and lifecycle-aware components.

Key Changes

  • Architecture Migration: Replaced ViewModels with Decompose components across all screens
  • Component Lifecycle: Implemented proper component lifecycle management with LifecycleRegistry and instanceKeeper
  • State Management: Migrated from MutableStateFlow to Decompose's MutableValue and Value for reactive state
  • Navigation: Updated navigation logic to work with Decompose's component-based approach
  • Dependency Injection: Adjusted DI setup to support Decompose components

Technical Highlights

  • Created DefaultComponent implementations for all major screens (Dashboard, Habits, Projects, Settings)
  • Implemented proper lifecycle handling to prevent memory leaks
  • Maintained existing business logic while modernizing the presentation layer
  • Ensured compatibility with Kotlin Multiplatform requirements

Files Modified

  • Dashboard, Habits, Projects, and Settings screens migrated to Decompose components
  • Navigation and routing updated for component-based architecture
  • Lifecycle management and state handling modernized

🤖 Generated with Claude Code

claude and others added 4 commits January 30, 2026 16:51
Defines the full plan to replace all ViewModels and Jetpack Compose
Navigation with Decompose Components, nested Child Stacks, Kodein
DIAware pattern, and Essenty lifecycle-coroutines.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit migrates the entire JetHabit application from Jetpack Compose
Navigation + androidx.lifecycle.ViewModel to Arkadii Ivanov's Decompose library.

Changes:
- Add Decompose (3.2.0-alpha05) and Essenty (2.2.0-alpha02) dependencies
- Remove compose-navigation and compose-viewmodel dependencies
- Create RootComponent with Child Stack managing Splash/Main/Create flows
- Create MainComponent managing bottom navigation with 5 tab stacks
- Replace all ViewModels with Decompose Components:
  * DailyListComponent, DetailComponent
  * HealthListComponent, TrackHabitComponent, CreateHabitComponent
  * StatisticsComponent, ChatComponent
  * ProfileStartComponent, EditProfileComponent, SettingsComponent, ProjectListComponent
- Update all Screen composables to use Components instead of ViewModels
- Replace MutableStateFlow with MutableValue from Decompose
- Replace viewModelScope with coroutineScope(Dispatchers.Main) from Essenty
- Adopt proper Kodein DIAware pattern (remove Inject service locator)
- Update platform entry points (Android, iOS, Desktop) to create RootComponent
- Delete BaseViewModel, all ViewModel files, and navigation infrastructure
- Preserve all business logic, state management, and UI

Benefits:
- Multiplatform lifecycle management
- Type-safe navigation with serializable configs
- Better state preservation for nested stacks
- Proper dependency injection pattern

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Fixed lifecycle issues where child components were reusing parent ComponentContext
- Added proper childContext() calls to create isolated lifecycle scopes for child components
- Added missing navigation imports (pop, push) to Daily, Health, and Profile components
- Removed 'private' modifier from config parameters to allow proper factory usage
- Fixed Statistics and Chat components to use proper child contexts in MainComponent

This ensures proper cleanup and prevents memory leaks by giving each component
its own lifecycle scope.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants