Daniele B
09/14/2020, 3:53 PMambientOf
in this way, which is basically the same way you would use @EnvironmentObject
in SwiftUI:
https://kotlinlang.slack.com/archives/CJLTWPH7S/p1592352556316500
@Composable
fun foo(appState: StateFlow<ChannelState>) {
val currState by appState.collectAsState()
Providers(CurrAppState provides currState) {
// Content that should see currState
}
}
as a kind of “dependency injection”, which “saves” an object in the environment, so that it’s possible to call it down the tree without having it passed all the time as a parameter.
But I didn’t understand the explanation of @Adam Powell and @Zach Klippenstein (he/him) [MOD] why ambientOf
should not be used in this use case, and what is the way to use it instead.Adam Powell
09/14/2020, 5:45 PMDaniele B
09/14/2020, 5:54 PM@EnvironmentObject
on SwiftUIambientOf
is not to be used to have an environment object like in @EnvironmentObject
, what is it for and how should it be used?Adam Powell
09/14/2020, 6:25 PMThreadLocal
to get information into a regular function call as opposed to via parameter passing, you should similarly feel strange about using ambients to provide information to composable function callsSean McQuillan [G]
09/14/2020, 6:34 PMDaniele B
09/14/2020, 6:39 PM