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

Tristan

05/27/2020, 1:38 AM
Hello, In the Jetnews app, I saw we are using an AppContainer which contains the variables we will share across the app (such as repositories). We have to pass down this object to each component. What prevent us from using ambient?
☝️ 2
m

molikto

05/27/2020, 6:05 AM
I am using Ambient. only that I need to write
val controller = controller
all the time, because the
controller
is accessed inside
onClicks
(you cannot call composible inside these)
a

Adrian Blanco

05/27/2020, 7:01 AM
I'm sure Ambient would work, however the problem with Ambient is that eventually it would lead to a lot of implicit dependencies and then you might have to deal with a lot of bad things in runtime instead of compile time. So I'm guessing that's why they were avoided
t

Tristan

05/27/2020, 11:37 AM
I understand the concerns @Adrian Blanco , but I think having all the parents asking for parameters they will only use for a single component is also source of troubles. When we will remove our child component, we will have a dependency we don’t need anymore. What can be done is to use Ambiant at parent level of a component that doesn’t need to hold specific code. Usually I ask myself “Can I use this in another project”? If so, no ambiant inside (unless it’s for theming or so)
c

carbaj0

05/27/2020, 4:49 PM
https://twitter.com/mjackson/status/1195431511417208834 this could be a interesting thing to read, I think that context (react) and ambients are similar concepts
👍 1
a

Adrian Blanco

05/27/2020, 4:57 PM
I think this will probably be one of the things that will get a lot more of attention and care in the future. There's also a ton of potential with inverting the dependencies where instead of having the compose view handle everything, you could have business logic nodes (eg react component equivalent) which use eg dagger and supply simple compose views.
👍 1
t

Tristan

05/27/2020, 5:03 PM
Thanks for sharing
14 Views