zak.taccardi
07/27/2020, 10:18 PMval isLoggedIn: Flow<Boolean>
that can emit true
or false
in any order and multiple times each - what would be the best way to observe when it switches from true
to false
? I would like to run a function when the user logs out - meaning the Flow<Boolean>
emits true
then false
?
val isLoggedIn: Flow<Boolean>
isLoggedIn
// <-- what operators do I need here?
.onEach {
onLogout()
}
.launchIn(scope)
Tim Malseed
07/27/2020, 10:21 PMdistinct
, and then just check if your value is false
in you onEach
block?Zach Klippenstein (he/him) [MOD]
07/27/2020, 10:21 PM.distinctUntilChanged()
.filter { it }
zak.taccardi
07/27/2020, 10:23 PMTim Malseed
07/27/2020, 10:26 PMfilterNot { it }
zak.taccardi
07/27/2020, 10:26 PMfalse
- won’t it emit and incorrectly call onLogout()
true
to false
flow { emit(false) }
should not trigger the onLogout()
Tim Malseed
07/27/2020, 10:29 PMzak.taccardi
07/27/2020, 10:35 PM.distinctUntilChanged()
.drop(1)
.filterNot { it }
false
would not pass through the filter, but false, true, false
would and true, false
would as wellTim Malseed
07/27/2020, 10:39 PMsatyan
07/28/2020, 2:04 PMareEquivalent(old,new)
parameter of distinctUntilChanged to only match old = true and new = false