AFAIU, @WrappedStore
behaves the exact same way as using a store
property and an @ObservedObject var viewStore
.
DynamicProperty
works in the same way as View
in that it only triggers a reload when either a value type property is mutated, or it receives an objectWillChange
signal – there's no way for it to know that a reference type was mutated otherwise.
I tested the view reload count using both methods – you can find the gist with the code here.
This is when using @WrappedStore
:
And this is when using the store
property / @ObservedObject var viewStore
:
So, @WrappedStore
is equivalent when you're just scoping the store down each view.
I agree, though, that right now we can't observe only a certain ViewState
when using @WrappedStore
, although I'm working on it right now.
Firstly, it would have to be a new property wrapper, since it introduces a third generic type for the new local state, and I wouldn't want to force the user of @WrappedStore
to specify a third generic type which would be equivalent to the first. Let's call this property wrapper @WrappedStoreLocal
.
The main issue is that is needs to phases of initialisation: one where the user passes in the closure/keypath which would convert parent state into the local state, and another where the caller passes in the store. This is simply not possible right now with property wrappers – here's a gist with my best try at an implementation of @WrappedStoreLocal
.
I'd love to hear any solutions for this!