Brandon Trautmann
06/18/2020, 4:58 PMviewModelScope.launch {
customerRepo.customer(customerUid) // Returns a `Flow<Customer>`
.combine(controllerRepo.controllersForCustomer(customerUid)) { customer, controllers ->
CustomerWithControllers(customer, controllers)
}
.collect { customerWithControllers ->
internalState.value = State.Loaded(customerWithControllers)
}
}
This works just fine, but when I go to delete a customer
, the deletion cascades to the controllers
and what you end up with is a new CustomerWithControllers
with empty controllers because the customer
Flow
last emission was the customer that was just deleted. I solved this by holding onto the Job
returned by launch
, and when I go delete a customer, I basically cancel that Job
, delete the customer, and then execute a function that checks for the existence of any customer and if one doesn't exist, brings the user to a FTUX screen. Is this a decent way of handling this? It'd be nice if Room
had some way to emit an Empty
token or something to indicate the table is empty 🤔Empty
token in Room)... Another way of asking would be "is combine
a good idea here?"Flow
return a nullable type, so that may be the direction I have to go!rkeazor
06/21/2020, 7:36 AMcontrollerRepo.controllersForCustomer(customerUid))? upon a valid return of customerRepo.customer(customerUid)