Is there any difference between this two?
private val _userReviewData = MutableSharedFlow<Resource<ReviewResponse>>()
val userReviewData get() = _userReviewData.asSharedFlow()
OR
private val _userReviewData = MutableSharedFlow<Resource<ReviewResponse>>()
val userReviewData = _userReviewData.asSharedFlow()
I don't understand any diff yet!
Also .asSharedFlow()
should I defined explicitly or not?
CodePudding user response:
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.