TGTGInsighttelegram intelligenceLIVE / telegram public index
← Android Broadcast
Android Broadcast avatar

TGINSIGHT POST

Post #9015

@android_broadcast

Android Broadcast

Vues6,490Nombre de vues
Publié27 avr.27/04/2025 04:58
Contenu

Contenu du post

Reanimator - простоя библиотека для Jetpack ViewModel (с поддержкой KMP) для работы с состоянием. Подробный разбор в статье (EN,11м) или альтернативной ссылке @Serializable data class MyUiState( // Persistent val data: List<String> = emptyList(), val selectedItem: String? = null, // Transient val isLoading: Boolean = false, val error: String? = null ) class MyViewModel(private val savedStateHandle: SavedStateHandle) : ViewModel() { // Define which properties are transient private val transientProps = listOf("isLoading", "error") // Declare your state flow - Reanimator handles the rest! private val _uiState by savedStateHandle.getMutableStateFlow( defaultValue = MyUiState(), // Initial/default state coroutineScope = viewModelScope, // Scope for saving changes transientProperties = transientProps // What NOT to save // key = "custom_state_key" // Optional: custom key ) val uiState: StateFlow<MyUiState> = _uiState.asStateFlow() // ... rest of your ViewModel logic ... fun updateData(newData: List<String>) { // Just update the state - Reanimator saves persistent parts automatically _uiState.update { it.copy(data = newData, isLoading = false) } } } #android#kmp