https://kotlinlang.org logo
j

Jan Skrasek

08/29/2020, 7:25 PM
Ambients - why sometimes ambients are "registered" with the value directly and sometimes you pass a remembered state of the value? What's is the logic/meaning behind this? I thought that there is already a logic in ambient how to compare new provided value to the previous.
a

Adam Powell

08/29/2020, 7:26 PM
do you have an example?
j

Jan Skrasek

08/29/2020, 7:28 PM
ConfigurationAmbient - it is a remembered state vs. ContextAmbient - context is passed directly.
a

Adam Powell

08/29/2020, 7:32 PM
ah. `ConfigurationAmbient`'s wireup to get changed values is a bit different in the implementation details and could probably be simplified a bit. It's remembering an observable state holder so that the
Providers
call recomposes when it changes via the callback.
There is indeed logic in ambient to compare the provided values, the implementation there is to wire up the observation for when the host view's configuration changes.
Context doesn't change for a view after construction so it doesn't come up there.
j

Jan Skrasek

08/29/2020, 7:34 PM
So when the provided value for ambient is not remembered state, recomposition ambient value can be caused done only by new Providers() call?
a

Adam Powell

08/29/2020, 7:36 PM
A new Providers call is the only way an ambient value can change
For Configuration, recomposition based on reading the MutableState holder is causing a new Providers call
j

Jan Skrasek

08/29/2020, 7:49 PM
For Configuration, recomposition based on reading the MutableState holder is causing a new Providers call
Aha moment, obvious now! Thanks a lot.
👍 1