Would you remind me please, what hack is being sug...
# android-architecture
g
Would you remind me please, what hack is being suggested by Google nowadays instead of
SingleLiveData
? I remember they've created it and were discouraging its usage after.
d
No it won’t
This is an anti pattern.
Check out this thread where we have an in depth discussion about this topic with a Google Employee.
But I guess you are aware of it being a hack so you know what you are getting yourself into.
g
Wow, I didn't know that. Thanks for pointing it out 😄
r
A google Employee may call it a anti pattern. But it was still mentioned at Google IO, and its reference in the google doc, so I dont think it's that much of a anti pattern... I see it used in production with no problem
g
it's a strawman argument tho, nobody is questioning that it works. The whole discussion is a bit theorethical and more around idiomacy and doing things right, not just doing works for me things. And the google employee has a point but not a solution yet... So yeah, in a meantime, pragmatically speaking, I'll keep using same hacks as you do, which doesn't make it less of an anti-pattern.
1
d
The end does not justify the means.
What about placing a
Flow
into the state object itself?
Yeah I think that's a bad idea because a
Flow
can also be hot.
If it was a pure cold
Flow
it would be ok.
r
Flow is pure cold
it needs a channel to be hot
Not sure how it being hot or cold changes anything... @ghedeon I agree with you, its def a good argument. But its at a fine line. For instance , how is wrapping it in a Event object really a anti pattern. You don't effect the observer in any way. and all you do is check if the event is handled when its posted.But I can see the argument ,that it doesn't completely reflect state. but Its hard to say at that point
d
Yes it needs a channel to be hot and that's the problem. Putting a
Flow
in the state object could be an elegant way to attach the needed series of events associated to that state. But only if it's a cold
Flow
, a
Flow
emitting from a channel is NOT OK IMHO. If you could guarantee that the
Flow
in state is cold then I am not opposed to that.
r
Lol I'm lost.Flow handles cold streams not hot stream. And the flow would need to be hot to handle events.
Because events can happen at any time
d
Reducer updates the state and now a
Snackbar
need to be shown in relation to that state change. So we attach a
Flow
to the state that emits a single
ShowSnackbarMessage
event. If the
Flow
in the state object is backed by a
Channel
then it could continue to emit events.
My question is if this is an OK way to handle the event problem.