Arsen
04/17/2021, 12:47 PMdata class Node(
val name: String,
val children: List<Node>
)
I want to follow UDF + single source of truth. Level of depth is unknown (assume it's unlimited). How to follow immutability for updates (add/remove node) in this case if i should at all. Maybe it worth to try mutable state, but idk how to cook mutable state with compose and don't break recomposition.Dominaezzz
04/17/2021, 12:51 PMArsen
04/17/2021, 12:54 PMArsen
04/17/2021, 12:58 PMDominaezzz
04/17/2021, 1:08 PMArsen
04/17/2021, 1:10 PMDominaezzz
04/17/2021, 1:12 PMAdam Powell
04/17/2021, 1:51 PMmutableStateListOf()
to back that children listAdam Powell
04/17/2021, 1:53 PMdata class
Arsen
04/17/2021, 2:26 PMArsen
04/17/2021, 2:28 PMArsen
04/17/2021, 2:35 PMArkadii Ivanov
04/17/2021, 2:38 PMArsen
04/17/2021, 2:39 PMArsen
04/17/2021, 2:40 PMArkadii Ivanov
04/17/2021, 2:40 PMArsen
04/17/2021, 2:42 PMArkadii Ivanov
04/17/2021, 2:43 PMArsen
04/17/2021, 2:44 PMAdam Powell
04/17/2021, 2:45 PMArsen
04/17/2021, 2:47 PMArkadii Ivanov
04/17/2021, 2:50 PMAdam Powell
04/17/2021, 2:50 PMArsen
04/17/2021, 2:52 PMAdam Powell
04/17/2021, 2:55 PMmutableState[List|Map]Of
functions, is under the hood implemented by process-wide immutable data structures. If you take a snapshot, (which compose does when it performs recomposition,) then all snapshot state objects in the process are consistent with one another in that snapshot. Think of each snapshot state object as a pointer into a big immutable data structure: the snapshot itself.Adam Powell
04/17/2021, 2:56 PMAdam Powell
04/17/2021, 3:00 PMMutableFoo
as opposed to just a Foo
that only exposes read accessAdam Powell
04/17/2021, 3:06 PMnode.copy(children = children.mapNotNull { changedOrExistingValueOrNullIfRemoved(it) })
plus or minus some optimizations for fully unmodified nodesAdam Powell
04/17/2021, 3:08 PMList<T>
is not assumed to be stable, so if you want to make this promise about your nodes you should mark the node class as @Stable
Adam Powell
04/17/2021, 3:10 PMhashCode
is particularly inefficient if you find yourself using it, as it will end up traversing the whole subtree every time it's called. You'll probably want to implement your own that caches, and the usefulness of `data class`'s conveniences will dry up pretty quickly.Rick Regan
04/17/2021, 3:33 PMAdam Powell
04/17/2021, 3:37 PMAdam Powell
04/17/2021, 3:38 PMSnapshot.withMutableSnapshot {}
. That defines a single isolated snapshot transaction.Adam Powell
04/17/2021, 3:39 PMAdam Powell
04/17/2021, 3:40 PMSnapshot.sendApplyNotifications()
, which commits the current global transaction state and may in turn schedule recompositionAdam Powell
04/17/2021, 3:41 PMRick Regan
04/17/2021, 3:43 PMArsen
04/17/2021, 3:58 PMArsen
04/17/2021, 9:05 PMAdam Powell
04/17/2021, 11:25 PMkey(item) {}
in your loop to associate item identity with each one rather than just the index orderArsen
04/17/2021, 11:37 PMArsen
04/17/2021, 11:37 PMArsen
04/17/2021, 11:44 PMArsen
04/17/2021, 11:48 PMAdam Powell
04/18/2021, 12:50 AMremember {}
in the node composable, store it in the NodeModel
Adam Powell
04/18/2021, 12:50 AM@Composable fun
as a visitor of your data, which leaves your data as accessible as you likeArsen
04/24/2021, 8:51 PM