-
Notifications
You must be signed in to change notification settings - Fork 16
Add binding onSet demo #37
Add binding onSet demo #37
Conversation
That's a really cool view! Thanks for writing it! Unfortunately, the implementation violates the "Single source of truth" principle by having two state variables kind of "for the same thing". What I mean by this is that the statuses can (and should) be calculated based on the password. Instead of using About DocC For editing the tutorial, you can:
The preview does not work for the actual documentation (including articles) for some reasons, only for tutorials. As the |
Hello David, I hope you are doing well. Apologies for the delayed reply but I got swamped with work 😅
I am glad you decided to keep this example as I want to contribute to the project one way or another! I will be happy to do any necessary adjustments so that we can merge it.
Thank you for the detailed explanation and for updating the code. This is exactly what I was hoping for when submitting this PR, an opportunity to learn something new and improve. I am generally aware of the "Single Source Of Truth" (SSOT) principle in software development, things like using API call data vs database cache data etc but after doing some research (https://developer.apple.com/videos/play/wwdc2020/10040/) it seems to also be particularly prevalent in SwiftUI. SSOT as a GUI paradigm is a new concept to me but If understood correctly the issue was although
It does make sense, but then I wonder as you also mention below:
Under what circumstances should Furthermore, I was pleasantly surprised to see that through the use of computed properties async is not even needed any more which greatly simplifies the example. I guess this is because each checker keeps track of its own value through the computed property and just gets updated as it changes. This however raises another question. If you remember, what started all this is that I wanted to react to a user typing into an Basically what I am asking is whether the statement that async is not necessary to update multiple values at the same time is correct or not.
Thank you for explaining how to install DocC. I got it working and managed to load up the preview. It looks fantastic by the way!
Understood, that would be no problem. I will be happy to create a new article once I have a deeper understanding of how things work hence my questions above 😇 In the meantime can you please let me know what changes are needed to proceed? Things like:
In terms of:
I guess we will need a new demo for that, so I will try to think of something more suitable. |
It can be used e.g. for debugging (detecting which view updates state), or when you have two state properties which are basically independent, but if one of them changes a certain way, you want to update the other one. As an example, take this line which removes the last element of an array if the user closes a dialog and another state value has a certain value, which it also updates. This might get quite complicated using a completely declarative approach with state values, so
Yes, async is not required for simple updates of values, it might be necessary if a state value depends on a process which is async in general (such as downloading images), that's why
Nice, thanks! 👍
I like the form section's title "Password Checker". I think we could replace "Binding Reactor" by "Password Checker".
I think the modal approach is good.
There is the Idle Demo with the progress bar example, but it might make sense to add an example for another common task such as networking (as the progress bar demo is an example for a repetitive task without really fetching any data or so). |
Hello David, this should now be ready for a second review! Please let me know if any more changes are needed. Thank you! |
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.
Thank you!
Steps
Purpose
Relates to #33
Update the Demo application to include a demo of how to use the binding's
onSet
in order to react to changes to the binded variable.Approach
The demo is using the EntryRow's
text binding
and is presented in the form of a rudimentary password validation form. The password is being checked while the user is typing in an async fashion where each validation check is dynamically updated with a visual indicator displaying its status. The validation statuses are buttons which on press display some information regarding the checks being performed as a popup dialog. The demo also shows how to correctly update from asynchronous contexts usingIdle
.References
Demo
Screencast.from.2024-06-17.09-58-47.webm
Notes
onSet
and how to update from asynchronous contexts? Let me know what you think.Thank you for your time and consideration for this PR!