Created
August 4, 2023 07:57
-
-
Save mzfkr97/2706e6d1c74b409863951e94912c4292 to your computer and use it in GitHub Desktop.
delegate
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
package com.slutsk.roman.slutsktransp.presentation.delivery.viewmodel | |
import androidx.lifecycle.ViewModel | |
import androidx.lifecycle.viewModelScope | |
import com.slutsk.archkit.viewmodel.ViewStateDelegate | |
import com.slutsk.archkit.viewmodel.ViewStateDelegateImpl | |
import com.slutsk.roman.slutsktransp.core.extension.EMPTY_STRING | |
import com.slutsk.roman.slutsktransp.core.providers.ResourceProvider | |
import kotlinx.coroutines.flow.Flow | |
import kotlinx.coroutines.launch | |
import javax.inject.Inject | |
data class DeliveryState( | |
val delivery: String = EMPTY_STRING | |
) | |
interface DeliveryDelegate { | |
val deliveryState: Flow<DeliveryState> | |
context(ViewModel) | |
suspend fun getDelivery() | |
context(ViewModel) | |
suspend fun updateDelivery(title : String) | |
} | |
class DeliveryDelegateImpl @Inject constructor( | |
private val resourceProvider: ResourceProvider | |
) : DeliveryDelegate, | |
ViewStateDelegate<DeliveryState, Unit> by ViewStateDelegateImpl(DeliveryState()) { | |
override val deliveryState: Flow<DeliveryState> | |
get() = viewState | |
context(ViewModel) | |
override suspend fun getDelivery() { | |
viewModelScope.launch { | |
reduce { | |
it.copy( | |
delivery = "getDelivery: " | |
) | |
} | |
} | |
} | |
context(ViewModel) | |
override suspend fun updateDelivery(title : String) { | |
viewModelScope.launch { | |
reduce { | |
it.copy( | |
delivery = "updateDelivery value ${title}" | |
) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment