ReedCopsey / Gjallarhorn.Bindable

Unidirectional binding library built on top of Gjallarhorn for WPF and Xamarin Forms
MIT License
27 stars 10 forks source link

Documentation/examples #8

Open cmeeren opened 6 years ago

cmeeren commented 6 years ago

I'm intrigued by this concept, although I'm at a bit of a loss as to how it should be used, not least because Gjallarhorn seems to be mutable at its core and Gjallarhorn.Bindable talks about a "fully immutable data model".

Could you provide or link to any documentation or examples? (I've seen the API reference, and it doesn't really explain how to use it.)

FoggyFinder commented 6 years ago

You can find some examples here and there is a very great article

Christmas Trees in WPF, 2016 Edition

but API was changed so some function has different names.

cmeeren commented 6 years ago

Thanks. While intriguing, the samples were complex enough (contained so many nontrivial, unexplained concepts) that I'll have to wait for proper documentation before I delve further into this.

FoggyFinder commented 6 years ago

@cmeeren It's really much simpler than it would appear at first sight. Just curious what would you like to see at the documentation?

Btw, I saw in your profile the Yarni - It seems like you already know concept (cause as I know Redux was inspired by Elm). So I really can't understand what exactly is causing you difficulties.

cmeeren commented 6 years ago

I understand the basic concepts, and I'm sure the rest is simpler than it appears at first sight, but without documentation to set the record straight, I only have "first sight" and my own guesses to go on. Some general things I'm unsure about:

Slight tangent: I'm also unsure of if/how Gjallarhorn.Bindable has fixed a really annoying problem I have with my current redux-based Xamarin.Forms app: I have the text values of all Entry views in the store so I can control these values (prefill values, clear password fields after successful password change, etc.) and do other logic based off them (enable/disable submit buttons, show validation messages, etc.), but that means every character typed into a text field (based on Entry.TextChanged) goes through the entire redux loop, ultimately resulting in Entry.Text being set programatically (directly or through updating the BindingContext to a new immutable view model, I'm doing the latter) to the value the user just typed. In addition to some slowness, this causes problems since by updating Entry.Text, we're potentially triggering TextChanged again (if the user typed another character before the update loop completed, which is entirely possible), potentially resulting in an infinite loop where the value is changed back and forth. (I've "solved" this by wrapping the TextChanged handlers that dispatch actions in functions that only proceed if a mutable bool update field in the codebehind is false, and I set this to true before changing the BindingContext to the new VM and restore it to false afterward, but this causes a race condition of sorts wherein characters typed by the user can be swallowed and get lost if they occur during the BindingContext switch, this problem doesn't occur often but still more frequently than I'd like.)

FoggyFinder commented 6 years ago

"Some general things I'm unsure about:" @cmeeren That is nice - I think it's better to split the general question to many small questions (like you have done) and ask in the F# Slack (I know you already joined) or in the SO (there even special tag there) or maybe just create a new issue.

"that means every character typed into a text field (based on Entry.TextChanged) goes through the entire redux loop" I'm not familiar with redux concept - but maybe you can create separate component?(it's just a supposition, anyway I'd wait for an answer @ReedCopsey )