refactor: KMP best practices — androidx ViewModel, .update{}, navigateTo + docs - #14
Merged
Merged
Conversation
Add a prescriptive "Coding conventions" section to CLAUDE.md ported from the
sibling Bitkit AGENTS.md (shared/Android/iOS): androidx ViewModel + viewModelScope,
_state.update{} over .value=, koinViewModel routes, navigateTo, immutable-collection
guidance. Fix the eco -> echo package typo.
Reconcile Architecture.md with the v1 reality: repositories are Pubky-only with an
in-memory session cache (no SQLDelight, no multiplatform-settings), secrets via
SecureSessionStore/KVault, SKIE not yet wired. Mark SQLDelight/SKIE sections as
not-adopted/future rather than current design, and point conventions back to CLAUDE.md.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Introduce NavController.navigateTo(route, builder) which skips navigation when the route is already the current destination, guarding against duplicate destinations from rapid taps or re-emitted navigation effects. Route all EchoNavigation call sites through it instead of raw navController.navigate. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Migrate all 15 shared ViewModels off the hand-rolled CoroutineScope/onDispose()
pattern to the multiplatform androidx.lifecycle.ViewModel + viewModelScope, and
standardize every state write on _state.update{} (removing the remaining _state.value=
sites). viewModelScope cancels in onCleared(), so the manual disposal is gone.
- deps: add androidx-lifecycle-viewmodel and koin-core-viewmodel to commonMain
- DI: bind ViewModels with Koin's viewModel{} DSL in SharedModule
- Android routes: resolve via koinViewModel() and drop the DisposableEffect onDispose
blocks; navigation lifecycle now owns the VM
- tests: drive viewModelScope via Dispatchers.setMain(StandardTestDispatcher) instead
of injecting a scope
Verified: detektAll clean, :shared:allTests (commonTest + iOS sim + Android unit) green,
composeApp builds, and an on-emulator smoke run (onboarding -> home -> decks -> discover
-> profile -> paste import) resolves every VM with no DI or lifecycle crashes.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What & why
Aligns Echo's shared presentation layer and the project docs with current KMP best practices, drawing on the conventions proven in the sibling Bitkit apps (
synonymdev/bitkit-android/bitkit-iosAGENTS.md).Three problems addressed:
_state.value =, 9 used_state.update {}.CoroutineScope(SupervisorJob() + Dispatchers.Main)+ manualonDispose(), despite the build already shipping the JetBrains KMPandroidx.lifecycle+koin-compose-viewmodel.Architecture.mddocumented SQLDelight, multiplatform-settings, and SKIE as the design; none exist in the build (Pubky-only + in-memory cache). Both docs also had aneco→echopackage typo.Changes (3 atomic commits)
CLAUDE.md(shared/Android/iOS); reconcileArchitecture.mdto v1 reality (SQLDelight/SKIE marked not-adopted/future); fix package typo.NavController.navigateTo()that dedups the current destination; allEchoNavigationcall sites routed through it.androidx.lifecycle.ViewModel+viewModelScope, every state write uses_state.update {}, DI binds VMs with Koin'sviewModel {}DSL, Android routes resolve viakoinViewModel()(dropping theDisposableEffect/onDisposeblocks), and the 4 VM tests driveviewModelScopeviaDispatchers.setMain(StandardTestDispatcher).kotlinx.collections.immutablefor UiState list fields is documented as a recommended follow-up (not in this PR).Verification
detektAllclean (0 findings):shared:allTestsgreen — commonTest + iOS simulator + Android unit (incl. the 4 migrated VM tests):composeApp:assembleDebugbuildsemulator-5554): onboarding auto-login → Home → Decks → Discover → Profile → Paste import (live preview +navigateTo); every VM resolves viakoinViewModelwith no DI or lifecycle crashes in logcat.🤖 Generated with Claude Code