[483] | 1 | define([ |
---|
| 2 | "dojo/aspect", |
---|
| 3 | "dojo/_base/array", |
---|
| 4 | "dojo/_base/lang", |
---|
| 5 | "dijit/_WidgetBase", |
---|
| 6 | "./_atBindingMixin", |
---|
| 7 | "dijit/registry" |
---|
| 8 | ], function(aspect, array, lang, _WidgetBase, _atBindingMixin){ |
---|
| 9 | return function(/*dijit/_WidgetBase...*/ w){ |
---|
| 10 | // summary: |
---|
| 11 | // Monkey-patch the given widget so that they looks at dojox/mvc/at set in them and start data binding specified there. |
---|
| 12 | // w: dijit/_WidgetBase... |
---|
| 13 | // The widget. |
---|
| 14 | |
---|
| 15 | array.forEach(arguments, function(w){ |
---|
| 16 | if(w.dataBindAttr){ |
---|
| 17 | console.warn("Detected a widget or a widget class that has already been applied data binding extension. Skipping..."); |
---|
| 18 | return; |
---|
| 19 | } |
---|
| 20 | |
---|
| 21 | // Apply the at binding mixin |
---|
| 22 | lang._mixin(w, _atBindingMixin.mixin); |
---|
| 23 | |
---|
| 24 | // Monkey patch widget.postscript to get the list of dojox/mvc/at handles before startup |
---|
| 25 | aspect.before(w, "postscript", function(/*Object?*/ params, /*DomNode|String*/ srcNodeRef){ |
---|
| 26 | this._dbpostscript(params, srcNodeRef); |
---|
| 27 | }); |
---|
| 28 | |
---|
| 29 | // Monkey patch widget.startup to get data binds set up |
---|
| 30 | aspect.before(w, "startup", function(){ |
---|
| 31 | if(this._started){ |
---|
| 32 | return; |
---|
| 33 | } |
---|
| 34 | this._startAtWatchHandles(); |
---|
| 35 | }); |
---|
| 36 | |
---|
| 37 | // Monkey patch widget.destroy to remove watches setup in _DataBindingMixin |
---|
| 38 | aspect.before(w, "destroy", function(){ |
---|
| 39 | this._stopAtWatchHandles(); |
---|
| 40 | }); |
---|
| 41 | |
---|
| 42 | // Monkey patch widget.set to establish data binding if a dojox/mvc/at handle comes |
---|
| 43 | aspect.around(w, "set", function(oldWidgetBaseSet){ |
---|
| 44 | return function(/*String*/ name, /*Anything*/ value){ |
---|
| 45 | if(name == _atBindingMixin.prototype.dataBindAttr){ |
---|
| 46 | return this._setBind(value); |
---|
| 47 | }else if((value || {}).atsignature == "dojox.mvc.at"){ |
---|
| 48 | return this._setAtWatchHandle(name, value); |
---|
| 49 | } |
---|
| 50 | return oldWidgetBaseSet.apply(this, lang._toArray(arguments)); |
---|
| 51 | }; |
---|
| 52 | }); |
---|
| 53 | }); |
---|
| 54 | |
---|
| 55 | return arguments; // dijit/_WidgetBase... |
---|
| 56 | }; |
---|
| 57 | }); |
---|