sync.js
2.73 KB
//>>built
define(["dojo/_base/lang","dojo/_base/config","dojo/_base/array","dojo/has"],function(f,m,x,k){function u(a,b,c,d,e,g,l,r,h,p){if(!(c(h,r)||"*"==e&&0>x.indexOf(d.get("properties")||[l],l)||"*"==e&&l in(p||{}))){c="*"==e?l:e;if(k("mvc-bindings-log-api"))var n=z(d,c,g,l);try{h=a?a(h,b):h}catch(t){k("mvc-bindings-log-api")&&console.log("Copy from"+n.join(" to ")+" was not done as an error is thrown in the converter.");return}k("mvc-bindings-log-api")&&console.log(n.reverse().join(" is being copied from: ")+
" (Value: "+h+" from "+r+")");f.isFunction(d.set)?d.set(c,h):d[c]=h}}var p=f.getObject("dojox.mvc",!0);k.add("mvc-bindings-log-api",(m.mvc||{}).debugBindings);var y,z=k("mvc-bindings-log-api")?function(a,b,c,d){return[[c.canConvertToLoggable||!c.declaredClass?c:c.declaredClass,d].join(":"),[a.canConvertToLoggable||!a.declaredClass?a:a.declaredClass,b].join(":")]}:"";m={from:1,to:2,both:3};y=function(a,b,c,d,e){var g=(e||{}).converter,l,r,h;g&&(l={source:a,target:c},r=g.format&&f.hitch(l,g.format),
h=g.parse&&f.hitch(l,g.parse));var m=[],n=[],t=f.mixin({},a.constraints,c.constraints),g=(e||{}).bindDirection||p.both,v=(e||{}).equals||y.equals;if(k("mvc-bindings-log-api"))var w=z(a,b,c,d);if("*"==d){if("*"!=b)throw Error("Unmatched wildcard is specified between source and target.");e=c.get("properties");if(!e){e=[];for(var q in c)c.hasOwnProperty(q)&&"_watchCallbacks"!=q&&e.push(q)}n=c.get("excludes")}else e=[b];g&p.from&&(f.isFunction(a.set)&&f.isFunction(a.watch)?m.push(a.watch.apply(a,("*"!=
b?[b]:[]).concat([function(b,f,e){u(r,t,v,c,d,a,b,f,e,n)}]))):k("mvc-bindings-log-api")&&console.log(w.reverse().join(" is not a stateful property. Its change is not reflected to ")+"."),x.forEach(e,function(b){if("*"!=d||!(b in(n||{}))){var e=f.isFunction(a.get)?a.get(b):a[b];u(r,t,v,c,"*"==d?b:d,a,b,void 0,e)}}));g&p.to&&(g&p.from||x.forEach(e,function(b){if("*"!=d||!(b in(n||{}))){var e=f.isFunction(c.get)?c.get(d):c[d];u(h,t,v,a,b,c,"*"==d?b:d,void 0,e)}}),f.isFunction(c.set)&&f.isFunction(c.watch)?
m.push(c.watch.apply(c,("*"!=d?[d]:[]).concat([function(d,e,f){u(h,t,v,a,b,c,d,e,f,n)}]))):k("mvc-bindings-log-api")&&console.log(w.join(" is not a stateful property. Its change is not reflected to ")+"."));k("mvc-bindings-log-api")&&console.log(w.join(" is bound to: "));q={};q.unwatch=q.remove=function(){for(var a=null;a=m.pop();)a.unwatch();k("mvc-bindings-log-api")&&console.log(w.join(" is unbound from: "))};return q};f.mixin(p,m);return f.setObject("dojox.mvc.sync",f.mixin(y,{equals:function(a,
b){return a===b||"number"==typeof a&&isNaN(a)&&"number"==typeof b&&isNaN(b)||f.isFunction((a||{}).getTime)&&f.isFunction((b||{}).getTime)&&a.getTime()==b.getTime()||(f.isFunction((a||{}).equals)?a.equals(b):f.isFunction((b||{}).equals)?b.equals(a):!1)}},m))});