1
2
3
4
5
6
7
| //>>built
| define("xstyle/core/Definition",["xstyle/core/utils","xstyle/core/es6"],function(h,k){function l(b){(this.computeValue=b)&&b.reverse&&this.setReverseCompute(b.reverse)}function q(b,a,c){if(a&&a.forElement)return{forElement:function(d){d=a.selectElement?a.selectElement(d):d;var e=["_cache_"+b.id];if(e in d){var f=d[e+"observe"];f.addKey&&f.addKey(c);return d[e][c]}var m=d[e]=a.forElement(d),g=d[e+"observe"]=n(b,m,c,{elements:[d]});d.xcleanup=function(b){b&&k.unobserve(m,g)};return m[c]}}}function n(b,
| a,c,d){var e=b._properties,f;"object"==typeof a&&(f=function(b){for(var a=0;a<b.length;a++){var c=e[b[a].name];c&&c.invalidate&&c.invalidate(d)}},k.observe(a,f),f.addKey&&f.addKey(c));return f}var p={},r=1;l.prototype={id:"x-variable-"+r++,cache:p,valueOf:function(){if((this.dependents||this._properties)&&this.cache!==p)return this.cache;var b=this,a=this.computeValue;if(a.then)return this.cache=a.then(function(a){b.computeValue=a;(a=b.cache=a())&&a.then&&a.then(function(a){b.cache=a});return a});
| (a=b.cache=a())&&a.then&&a.then(function(a){b.cache=a});return a},property:function(b){var a=this._properties||(this._properties={}),c=a[b];if(!c){var d=this,c=a[b]=new l(function(){return h.when(d.valueOf(),function(a){if(a&&a.forRule)return{forRule:function(c){c=a.selectRule?a.selectRule(c):c;var g=["_cache_"+d.id],e;if((e=g in c?c[g]:c[g]=a.forRule(c))&&e.forElement)return q(d,e,b);var f=c[g+"observe"];f&&(f.addKey?f.addKey(b):c[g+"observe"]=n(d,e,b,{rules:[c]}));return e[b]}};if(a&&a.forElement)return q(d,
| a,b);var c=d.cacheObserve;c?c.addKey&&c.addKey(b):c=d.cacheObserve=n(d,a,b);return a[b]})});c.key=b;c.parent=this;c.put=function(a){return h.when(d.valueOf(),function(c){function d(c){if(c.forElement)return{forElement:function(d){c.forElement(d)[b]=a}};c[b]=a}if(c.forRule)return{forRule:function(a){return d(c.forRule(a))}};d(c)})};c.id=this.id+"-"+b}return c},invalidate:function(b){var a=this.cacheObserve;a&&(k.unobserve(this.cache,a),this.cacheObserve=null);this.cache=p;var c,a=this._properties;
| for(c in a)a[c].invalidate(b);var d=this.dependents||0;c=0;for(a=d.length;c<a;c++)try{d[c].invalidate(b)}catch(e){console.error(e,"invalidating a definition")}},dependencyOf:function(b){(this.dependents||(this.dependents=[])).push(b)},notDependencyOf:function(b){for(var a=this.dependents||0,c=0;c<a.length;c++)a[c]===b&&a.splice(c--,1)},setReverseCompute:function(b){this.put=function(){var a=b.apply(this,arguments);this.invalidate();return a}},setCompute:function(b){(this.computeValue=b)&&b.reverse&&
| this.setReverseCompute(b.reverse);this.invalidate()},setSource:function(b){this.computeValue=function(){return b};this.invalidate()},observe:function(b){this.computeValue&&b(this.valueOf());var a=this;return this.dependencyOf({invalidate:function(){b(a.valueOf())}})},newElement:function(){return h.when(this.valueOf(),function(b){return b&&b.newElement&&b.newElement()})}};return l});
|
|