https://kotlinlang.org logo
#compose
Title
# compose
c

Colton Idle

01/23/2022, 7:37 PM
I've seen this pattern cropping up in some compose repos from others... thoughts? At first glance I guess it's kinda clever for trying to get something to launch only once, but it just seems bad
Copy code
LaunchedEffect(key1 = "launch_once") {
    myViewModel.doSomething()
  }
s

ste

01/23/2022, 7:40 PM
At first glance I guess it's kinda clever for trying to get something to launch only once
It's basically
LaunchedEffect(Unit)
, isn't it?
☝🏼 1
☝️ 2
☝🏽 1
3
a

Adam Powell

01/24/2022, 2:35 AM
Any constant will do but
Unit
is more or less what we standardized on.
true
had some support on the team for a while
LaunchedEffect(Unit)
is meant to look suspicious in the same way
while (true)
looks suspicious. The lack of a "real" key there is supposed to invite closer reading
2
we've had some discussion around whether this has been effective or if it's just kinda noisy. The discussion it invites I think is sort of anecdata suggesting some positive results
and in the case of the example that started the thread, the key should probably be
myViewModel
🙂
👍 1