Vsevolod Ganin
03/20/2021, 4:29 PMSideEffect
for atomicity on operation on local state? The doc is a bit unclear:
SideEffect can be used to apply side effects to objects managed by the composition that are not backed by snapshots so as not to leave those objects in an inconsistent state if the current composition operation fails.So this applies also to snapshot-backed objects when we need to make atomic change on them, right?
Adam Powell
03/20/2021, 4:30 PMAdam Powell
03/20/2021, 4:32 PMSnapshot.withMutableSnapshot {}
is one way to do this, but if you're making changes to snapshot-backed objects in a @Composable
function you don't need to do this explicitly, because compose always performs composition in a mutable snapshot of its own.Vsevolod Ganin
03/20/2021, 4:33 PMCrossfade
as an example. Inside you can see that there are consequent but not atomic ops on items
items.map …
items.clear()
keys.mapTo(items) …Shouldn’t it wrapped with
SideEffect
?Vsevolod Ganin
03/20/2021, 4:34 PMclear
but before maptTo
it is left inconsistent since targetChanged
is already used, isn’t it?Adam Powell
03/20/2021, 4:36 PMVsevolod Ganin
03/20/2021, 4:36 PM