juliocbcotta
12/28/2023, 10:13 AMJavier
12/28/2023, 10:42 AMStylianos Gakis
12/28/2023, 2:09 PMcurioustechizen
12/29/2023, 6:46 AMjuliocbcotta
12/29/2023, 6:27 PMZac Sweers
12/29/2023, 8:39 PMZac Sweers
12/29/2023, 8:40 PMjuliocbcotta
12/29/2023, 9:03 PMZac Sweers
12/29/2023, 9:04 PMArkadii Ivanov
12/29/2023, 9:29 PMval a = MyState(x = 1, onClick = { <capturing lambda> })
and val b = MyState(x = 1, onClick = { <capturing lambda> })
may not be equal
to each other.
Inability to serialize the state is another concerns. Looks incompatible with debugging tools like time travelling.Zac Sweers
12/29/2023, 9:50 PMArkadii Ivanov
12/29/2023, 9:58 PMdata class SomeScreenState(val x: Int, val onClick: () -> Unit)
Then you assigned this state somewhere in the screen's parent level (e.g. in Activity or something like that):
var lastSomeScreenState: SomeScreenState? = null
// at some point later
lastSomeScreenState = ...
Then you essentially leak the entire object hierarchy captured by onClick
. Even worse, you may leak your Activity
if you remember the state in Application
scope.
That's said, it's possible to avoid leaks of course, but it's pretty error prone, from my point of view.Arkadii Ivanov
12/29/2023, 9:59 PMZac Sweers
12/29/2023, 10:01 PMonClick
with something that holds any reference that shouldn’t be kept and still have the same problem. Better to make the wrong thing harder to doZac Sweers
12/29/2023, 10:02 PMZac Sweers
12/29/2023, 10:06 PM