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

Ji Sungbin

06/25/2022, 5:40 AM
Hi, I’m studying the inside of a compose SlotTable. Is the
invalidateGroupsWithKey(key: Int)
function in SlotTable only used for testing? I followed the final call of invalidateGroupsWithKey and arrived at the invalidateGroupsWithKey function with @TestOnly attached, and this function is not used. I figured out that the only use case of the
findEffectiveRecomposeScope(group: Int)
function, which is i think an important function of SlotTable, is invalidateGroupsWithKey, and I wanted to know where invalidateGroupsWithKey is called.
Copy code
@TestOnly
fun invalidateGroupsWithKey(key: Int) = HotReloader.invalidateGroupsWithKey(key)
And in the process of reaching final TestOnly function, I saw a function like the one below.
Copy code
fun invalidateGroupsWithKey(key: Int) {
    val compositions: List<ControlledComposition> = synchronized(stateLock) {
        knownCompositions.toMutableList()
    }
    compositions
        .fastMapNotNull { it as? CompositionImpl }
        .fastForEach { it.invalidateGroupsWithKey(key) }
     }
}
knownCompositions
is already a MutableList, but why change MutableList to MutableList?
2
a

Albert Chang

06/25/2022, 1:05 PM
The function is invoked by Studio to support hot reload (Live Edit). Obviously the purpose of
toMutableList()
is to create a copy of the original list.
🙏 2
j

Ji Sungbin

06/25/2022, 1:10 PM
Wow, how cool is it to call a function from AS! thank you! Thanks for the purpose of
toMutableList()
too!
8 Views