[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
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello!
I was wondering yesterday if we couldn't improve the
ViewStatestory in TCA, that is small observable sub-states forViewStores to work with instead of whole feature's states.I've made this quick proof of concept that observes each
KeyPathaccess to theViewStore's state and compare them with what's available in theState. IfStateoffers properties that are not used, it presents a runtime warning where it proposes aViewStatedeclaration.For example, activating this by using
.lookForViewStateOpportunities()in theAnimationcase study gives:
Likely overkill in this case, but the `ViewState` declaration is spot-on.This is of course not a perfect solution:
viewStore.stateand its descendants that are missed and considered unaccessed.ViewStoreaccesses 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 inGeometryReaders closures for example.KeyPath, for exampleviewStore.array.count, but I feel it should be possible to match them with more work.custom-dumpfacilities aroundKeyPaths, because establishing the link between aKeyPathand 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@BindableStateproperties.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'sremoveDuplicatesautomatically, 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
ViewStatedeclaration suggestion seems very enticing though.What do you think about it?
Beta Was this translation helpful? Give feedback.
All reactions