[dojo-contributors] Watchables, data bindings, and get/set
kzyp at dojotoolkit.org
Wed Mar 10 10:37:19 EST 2010
On 3/9/2010 9:49 PM, Bill Keese wrote:
> A few more comments/questions:
>> I wanted to propose having a pattern of providing the ability to monitor
>> stateful objects in dojo with a watch() method. The watch method would
>> be based on Mozilla's Object.prototype.watch :
>> obj.watch(propertyName, callback); // monitor a property
>> obj.watch(callback); // monitor any property change for that object
>> The two primary types of objects that I would like to be able to monitor
>> are widgets and data store objects. We have recently discussed using a
>> different data/object store approach whereby data store objects could be
>> provide a consistent set of methods, and watch() could certainly be one
>> of them. We could also easily add watch to dijit._Widget and deliver
>> notifications to listeners for any attribute changes. The ability to
>> watch an object would be discerned with feature detection (the presence
>> of obj.watch), but would hopefully be available at least on all widgets
>> (although user objects could implement this ability as well).
> Sounds cool, seems to supersede connections to widgets' attr() and
> onChange() methods.
> How would this be used with declarative widgets?
We could try to come up with some way of inserting watches in widget
declarations, although the primary use case is programmatic attribute
access that wishes to be notified of changes.
>> One of the primary motivations for this design, is would enable building
>> functionally reactive "live" templating engines or data-bindings on top
>> of Dojo. The concepts of functional reactive design (or data-bindings)
>> have been demonstrated in other projects like Flex, Flapjax , and Fin
>> . There recently has been interest expressed in developing a template
>> language with these type of data-binding capabilities that could run on
>> Dojo, where one could write something like:
>> And the variable/object property would be evaluated when the template is
>> executed, and the templating engine would then automatically "watch" the
>> obj's foo property for any changes and automatically rerender the
>> template when the value changes. This is a powerful concept because it
>> can remove a significant amount of user code for event propagation and
> Sounds cool. DTL already does this but having framework support too is
> a good thing.
Can you point me to how this works? I see in the code that there are
data events, but they seem like they would require manual triggering.
> Also, attributeMap is already designed for this purpose, it essentially
> sets up watches on specified widget attributes, and reflects those
> changes into the widget's DOM. I'm not against something better though.
I thought this was for routing attribute changes to DOM changes. How
would you monitor user-specified attributes from outside the widget with
More information about the dojo-contributors