[Experiment] ViewState opportunities suggestions #1225
tgrapperon
started this conversation in
Ideas
Replies: 1 comment
-
@tgrapperon Thanks for sharing! This looks like a lot of fun! Will try to take it for a spin soon 😄 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello!
I was wondering yesterday if we couldn't improve the
ViewState
story in TCA, that is small observable sub-states forViewStore
s to work with instead of whole feature's states.I've made this quick proof of concept that observes each
KeyPath
access to theViewStore
's state and compare them with what's available in theState
. IfState
offers properties that are not used, it presents a runtime warning where it proposes aViewState
declaration.For example, activating this by using
.lookForViewStateOpportunities()
in theAnimation
case study gives:This is of course not a perfect solution:
viewStore.state
and its descendants that are missed and considered unaccessed.ViewStore
accesses the properties. For example in modal/navigation contexts. I've added a small delay to the comparison to give it more time to unfold/evaluate all the body's hierarchy, like inGeometryReader
s closures for example.KeyPath
, for exampleviewStore.array.count
, but I feel it should be possible to match them with more work.custom-dump
facilities aroundKeyPath
s, because establishing the link between aKeyPath
and its property name is far from trivial. This doesn't work well with property wrappers right now, but it could hopefully be improved for a general purpose. In this case, this experiment could be updated to support@BindableState
properties.This is also not working well yet when already using a
ViewState
(for example, the one it suggested 😬)!The code was written in one go, in some hackathon/proof of concept style where I only wanted to see if it could work. There are of course many ways to refactor/reorganize it, or maybe rethink this at a deeper level. It is maybe possible to build the
ViewStore
'sremoveDuplicates
automatically, but I don't think it would be worth it performance-wise if it ever works.I'm not pushing it farther yet because of these issues. The
ViewState
declaration suggestion seems very enticing though.What do you think about it?
Beta Was this translation helpful? Give feedback.
All reactions