Manuel Unterhofer
06/16/2023, 12:46 PMremember
around derivedStateOf
? I believe the compiler plugin doesn’t derive them for me, does it? If so, is there a plan for a combined rememberDerivedStateOf
of some kind which does it?Stylianos Gakis
06/16/2023, 12:59 PMderivedStateOf
their state will be automatically observed. If you’re at the same time using some value from a non-state variable (say a param: T
as part of your composable) then that is not a state object, hence you need to key it.
Would you want this rememberDerivedStateOf
to magically try to find out if your objects are state objects or not?Manuel Unterhofer
06/16/2023, 1:08 PMrememberDerivedStateOf
cc @shikasdManuel Unterhofer
06/16/2023, 1:10 PMcan you magically make it so we don’t need to use state objects at all? That’d be even easierNot sure I agree, because having a state object is the whole point of it, isn’t it? Otherwise we could just use
remember
(minus the automatic dependency tracking we’re talking about here)Jorn Hertsig
06/16/2023, 1:10 PMStylianos Gakis
06/16/2023, 1:14 PMManuel Unterhofer
06/16/2023, 1:16 PMderivedStateOf
pretty hard to use correctly right now, and I can’t think of a better way to improve it
Maybe that design is even on purpose to nudge people into doing more recalculations instead of cluttering the runtime with overhead from tracking and invalidating calculation results, but I don’t know thatshikasd
06/16/2023, 1:40 PMremember
is already used.shikasd
06/16/2023, 1:41 PMderivedStateOf
for?Manuel Unterhofer
06/16/2023, 1:47 PMderivedStateOf
, and the previous implementation is based on exactly such a compiler plugin which automatically wraps the calculation with the captured values as keys. The patterns are always complex and expensive calculations, which means the code inside them might capture a lot of references and it will be tedious to extract all of them manually.
I believe such a pattern is the exact point where derivedStateOf
should help, but the manual management of `key`s makes it hard for us to switch.shikasd
06/16/2023, 1:50 PMderivedStateOf
that often to ensure caching works.
In some cases, it makes more sense to convert some of those changing values to mutableStateOf
instead.Manuel Unterhofer
06/16/2023, 1:51 PMshikasd
06/16/2023, 2:03 PMManuel Unterhofer
06/16/2023, 2:03 PMJustinBis
06/16/2023, 5:48 PMremember { derivedStateOf { } }
is a tricky API to use correctly. I'm not sure some magicDerivedStateOf { }
that is invalidated both by changes to the state objects it reads outside the composition and by changes to the params it reads that are local to the current composition would be easier to understand, but I think better lint / code inspection tools in the IDE would go a long way here. E.g. something as simple as warning when I'm reading a param from the composition but not using it as a key to remember would catch so many simple mistakes I've made.shikasd
06/17/2023, 12:38 PMexhaustive-deps
from eslint here :)