-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Wrap view store binding to avoid reading stale state #1802
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
"Yo Dawg, I heard you like bindings, so we put bindings into your bindings so you can bind while you bind!" Great find! I think that most of the problems are caused by the fact that the I'll try to give them a spin soon to check if I'm spotting issues. |
Nice catch @iampatbrown! I'm curious about the 'transaction($1)' purpose here. Could you explain it, please? Because removing this part still fixes both issues. |
@barabashd Toggle("Toggle", isOn: $isOn.animation(.easeIn)) Using |
@tgrapperon It's been a while since stumbling across the
Pretty sure the main thing was forwarding explicit binding animations/transactions. Accessing the current |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems to work great! We'll get a couple integration tests in place in another PR.
Fixes #1812. This regression was subtle, but it's better to retain the old crashing behavior than introduce this change since it's been with the library for a very long time, and we have workarounds like `ForEachStore`. We'll try to re-explore these subtle binding behaviors in the future.
Fixes #1812. This regression was subtle, but it's better to retain the old crashing behavior than introduce this change since it's been with the library for a very long time, and we have workarounds like `ForEachStore`. We'll try to re-explore these subtle binding behaviors in the future.
Attempt to fix #1800
The current method creates a binding with a location type of
ObservableObjectLocation
. By wrapping the binding the location type becomesFunctionalLocation
. Bindings that useObservableObjectLocation
seem to have their getter called while evaluating if a views inputs have changed. This doesn't seem to be the case withFunctionalLocation
. Which kind of makes sense.I've confirmed this works for #1783 and #1798 as well as checked animations work as expected.
@stephencelis @mbrandonw @tgrapperon maybe you can stress test this a bit to see if there are any unwanted effects. I imagine there is going to be some sort of optimisation that can be applied to bindings that use
ObservableObjectLocation
, but don't really think that's relevant here.