.referTo( value ) <-- Very cool feature

In all my years of software development, I had never done anything with "Data Binding"... First time I had ever used it or learned about it was in the past year and a half.  We had a project where we needed to use Adobe Flex which is built upon ActionScript.  In this language you hav what is referred to has Data Binding.   Where you can bind a variable to someting... Say a text box, so that if the value changes, the text box "automatically" changes itself without you having to manuly update the control... Very nice handy feature.

Would you say that the .referTo( value ) functionality is also considered "Data Binding?  It has the same affects as what you find in Adobe Flex.

Are there any limitations to using this?  Any pitfalls? Traps? 

Can this be used with user defined data types?  Say I have an employee object that has a name... Would I be able to do something like...
myTextControl.getTextValue.referTo( myEmp.firstName ) and would it know how to bind properly to the firstName property of myEmp object?


Anyway, very Very VERY cool feature!!

It is a pretty handy trick, heavily used in the introjucer for all its property components. Is it "data binding"? I don't know whether that jargon has a specific meaning or not, but I guess this is binding some data sources together.

Pitfalls - yes, probably lots! It won't deal with multithreading, you'd have to be careful to avoid loops in the dependency graph, I'm sure there are other perils. You could use it to pass any data that a var object can hold, so you could put custom types into a DynamicObject and pass that around, but whether that'd be a sensible use of it is doubtful, it's going to work best for simple var types.

Data binding? To me it sounds like MVC...

For web apps (my day time work) AngularJS kind of does the same.

I also discovered it last week and for me it's another JUCE gem!

Hey peter, I gotta ask... What's your thought on JavaScript?


Oh yeah - these are the best (binding the value objects).  You can of course get value objects from a bunch of the UI elements (sliders, buttons, etc), and bind these (and then your UI automatically updates when anything changes .. pretty slick).

Also - your entire project state can be a Valuetree, where the nodes refer to different values (which are also represented by the UI now).

And ... since we can dynamically assign the Value (referto will send out a change message), it is easy to have a "focused" object - and some corresponding UI that rebuilds itself every time the focus changes.

Really great stuff!  I found these a year ago and it has changed everything for me.

One thing to watch ... they are not thread safe out of the box (getValue / SetValue that is ).  So you may need to modify a bit if you are accessing from (for example) the audio thread.  There are a couple threads on this forum for creative ways to do that.


happy hacking!

If its only one variable, I wouldn't call it FRP, but if you take it to its logical conclusion you get something like:

* Elm Language
* Kivy
* RactiveJS

AngularJS is a poor example, not allowing expressions. In Kivy, I could enable/disable a save button based on whether the form is filled in:
enabled: firstName.text.length() > 0 && lastName.text.length() > 0 && etc...

Same with Elm, or RactiveJS, all three "calculate the dependencies" (reduce expressions) and make the magic happen.