Pedro Alberto
12/07/2021, 2:24 PMval <T> MutableStateFlow<T>.readOnly
get() = this as StateFlow<T>
now I realised there is a function called asStateFlow()
but when you go into asStateFlow the function does something different
public fun <T> MutableStateFlow<T>.asStateFlow(): StateFlow<T> =
ReadonlyStateFlow(this, null)mkrussel
12/07/2021, 2:30 PMReadonlyStateFlow is so consumers of the flow cannot cast back to MutableStateFlow and change the values. Similar to unmodifiableList in Java.Pedro Alberto
12/07/2021, 2:33 PMPedro Alberto
12/07/2021, 2:33 PMmkrussel
12/07/2021, 2:37 PMasStateFlowPedro Alberto
12/07/2021, 2:38 PM// Backing property to avoid state updates from other classes
  private val _uiState = MutableStateFlow(LatestNewsUiState.Success(emptyList()))mkrussel
12/07/2021, 2:38 PMPedro Alberto
12/07/2021, 2:39 PMmkrussel
12/07/2021, 2:39 PMmkrussel
12/07/2021, 2:40 PMPedro Alberto
12/07/2021, 2:47 PMAdam Powell
12/07/2021, 3:28 PMAdam Powell
12/07/2021, 3:29 PMAdam Powell
12/07/2021, 3:32 PMPedro Alberto
12/07/2021, 3:46 PMval <T> MutableStateFlow<T>.readOnly
get() = this as StateFlow<T>
since we use sharedflow and sateflow everywhere and if we sum up it could have impact on a long run.