Mark Lurie
02/15/2023, 3:23 PMprivate val _invoiceIntroFlowState: MutableStateFlow<InvoiceIntroFlowState> = MutableStateFlow(InvoiceIntroFlowState(customizationData = InvoiceCustomizationResponseEntity()))
val invoiceIntroFlowState: StateFlow<InvoiceIntroFlowState> = _invoiceIntroFlowState.asStateFlow()
data class InvoiceIntroFlowState(
val uiStatus: UiStatus = UiStatus.NONE,
val error: Failure? = null,
val customizationData: InvoiceCustomizationResponseEntity
)
Any attempt to do any kind of deep-copy that i know doesn’t work for me to trigger the new state event:
_invoiceIntroFlowState.update { currentState ->
currentState.copy(
customizationData = currentState.customizationData.copy(
logos = another //updatedLogos.map { it.copy() }
)
)
}
Any help will be highly appreciatedubuntudroid
02/15/2023, 8:14 PMInvoiceCustomizationResponseEntity
looks like? Could it have a custom equals implementation that omits logos? And, as logos
seems to be a Collection and Collections in most cases are considered equal if their items are equal (and you are doing .map { it.copy() }
which doesn’t really change the contents from an equality perspective), logos
seems to be equal to another
.
I’d suggest to debug into MutableStateFlow.update()
and look especially close at the call to compareAndSet()
. I guess that it always returns true
for you right at the first star, and as prevValue
and nextValue
are equal, it is not changing the underlying value which in turn causes the flow to stay silent.
`compareAndSet()`’s doc says:
This function use a regular comparison using Any.equals. If both expect and update are equal to the current value, this function returns true, but it does not actually change the reference that is stored in the value.