Is there any difference between this two?
private val _userReviewData = MutableSharedFlow<Resource<ReviewResponse>>() val userReviewData get() = _userReviewData.asSharedFlow()
private val _userReviewData = MutableSharedFlow<Resource<ReviewResponse>>() val userReviewData = _userReviewData.asSharedFlow()
I don’t understand any diff yet!
.asSharedFlow() should I defined explicitly or not?
When you use
get() i.e. provide a custom getter, then every time you access
userReviewData, it will call
_userReviewData.asSharedFlow() which is unnecessary. It’s better to create a
SharedFlow instance once and use it instead of creating multiple such instances.
Answered By – Arpit Shukla