Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid using mutable stateflow to represent whole ui state #343

Open
atick-faisal opened this issue Dec 29, 2024 · 0 comments
Open

Avoid using mutable stateflow to represent whole ui state #343

atick-faisal opened this issue Dec 29, 2024 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@atick-faisal
Copy link
Owner

Avoid doing:

    private val _billingUiState = MutableStateFlow(UiState(BillingScreenData()))
    val billingUiState = _billingUiState.asStateFlow()

Instead, use this pattern more often when possible:

    val uiState: StateFlow<UiState<UserData>> = userDataRepository.userData
        .map { userData -> UiState(userData) }
        .catch { e -> UiState(UserData(), error = OneTimeEvent(e)) }
        .stateInDelayed(UiState(UserData(), loading = true), viewModelScope)
@atick-faisal atick-faisal added the enhancement New feature or request label Dec 29, 2024
@atick-faisal atick-faisal self-assigned this Dec 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant