calculated-cached-properties
Advanced tools
Comparing version 0.1.0 to 0.1.1
{ | ||
"name": "calculated-cached-properties", | ||
"description": "CalculatedCachedProperties allows properties to have values calculated by a function, and then cached. You can then manually invalidate the cache for one or more (or all) properties, forcing the function to invoked and recalculate next time the property is accessed. You can also set the value of property manually. Undefined / null etc are all valid property values. Works with POJSOs, JS constructors and CoffeeScript classes (i.e `MyClass extends CalculatedCachedProperties`). A spinoff from uBerscore library. Docs will follow, see the specs till then :-)", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"main": [ | ||
@@ -6,0 +6,0 @@ "build/dev/CalculatedCachedProperties.js", |
@@ -5,3 +5,3 @@ /** | ||
* CalculatedCachedProperties allows properties to have values calculated by a function, and then cached. You can then manually invalidate the cache for one or more (or all) properties, forcing the function to invoked and recalculate next time the property is accessed. You can also set the value of property manually. Undefined / null etc are all valid property values. Works with POJSOs, JS constructors and CoffeeScript classes (i.e `MyClass extends CalculatedCachedProperties`). A spinoff from uBerscore library. Docs will follow, see the specs till then :-) | ||
* Version 0.1.0 - Compiled on 2015-06-11 19:51:39 | ||
* Version 0.1.1 - Compiled on 2015-06-12 11:01:51 | ||
* Repository git://github.com/anodynos/calculated-cached-properties | ||
@@ -66,3 +66,3 @@ * Copyright(c) 2015 Angelos Pikoulas <agelos.pikoulas@gmail.com> | ||
cUndefined = { "cUndefined": true }; | ||
CalculatedCachedProperties.register = function (pojsoOrConstructor, calcProperties) { | ||
CalculatedCachedProperties.register = function (pojsoOrConstructor, calcProperties, isOverwrite) { | ||
var classConstructor, ctor, pojso; | ||
@@ -82,3 +82,3 @@ if (_.isFunction(pojsoOrConstructor)) { | ||
_.extend(ctor.calcProperties || (ctor.calcProperties = {}), calcProperties); | ||
pojso.defineCalcProperties(); | ||
pojso.defineCalcProperties(isOverwrite); | ||
} | ||
@@ -152,3 +152,3 @@ return pojsoOrConstructor; | ||
var cPropFn, cPropName, _ref; | ||
l.deb("Initializing cache for calculated properties of constructor named `" + this.constructor.name + "`"); | ||
l.deb("CalculatedCachedProperties: Initializing cache for calculated properties of constructor named `" + this.constructor.name + "`"); | ||
Object.defineProperty(this, cacheKey, { | ||
@@ -174,3 +174,3 @@ value: {}, | ||
return function (cPropName, cPropFn) { | ||
l.deb("...defining calculated property " + _this.constructor.name + "." + cPropName); | ||
l.deb("CalculatedCachedProperties: DEFINE calculated property " + _this.constructor.name + "." + cPropName); | ||
return Object.defineProperty(_this.constructor.prototype, cPropName, { | ||
@@ -183,5 +183,5 @@ enumerable: true, | ||
} | ||
l.deb("...requesting calculated property " + this.constructor.name + "." + cPropName); | ||
l.deb("CalculatedCachedProperties: GET value of calculated property " + this.constructor.name + "." + cPropName); | ||
if (this[cacheKey][cPropName] === cUndefined) { | ||
l.deb("...refreshing calculated property " + this.constructor.name + "." + cPropName); | ||
l.deb("CalculatedCachedProperties: CALCULATING & CACHING property " + this.constructor.name + "." + cPropName); | ||
this[cacheKey][cPropName] = cPropFn.call(this); | ||
@@ -195,2 +195,3 @@ } | ||
} | ||
l.deb("CalculatedCachedProperties: SET value of property " + this.constructor.name + "." + cPropName); | ||
return this[cacheKey][cPropName] = v; | ||
@@ -223,3 +224,3 @@ } | ||
if (this[cacheKey][p] !== cUndefined) { | ||
l.deb("...delete (via fn) value of property " + this.constructor.name + "." + p); | ||
l.deb("CalculatedCachedProperties: CLEAR (via function) value of property " + this.constructor.name + "." + p); | ||
this[cacheKey][p] = cUndefined; | ||
@@ -232,3 +233,3 @@ cleaned.push(p); | ||
if (this[cacheKey][ca] !== cUndefined) { | ||
l.deb("...delete value of property " + this.constructor.name + "." + ca); | ||
l.deb("CalculatedCachedProperties: CLEAR value of property " + this.constructor.name + "." + ca); | ||
this[cacheKey][ca] = cUndefined; | ||
@@ -235,0 +236,0 @@ cleaned.push(ca); |
@@ -5,3 +5,3 @@ /** | ||
* CalculatedCachedProperties allows properties to have values calculated by a function, and then cached. You can then manually invalidate the cache for one or more (or all) properties, forcing the function to invoked and recalculate next time the property is accessed. You can also set the value of property manually. Undefined / null etc are all valid property values. Works with POJSOs, JS constructors and CoffeeScript classes (i.e `MyClass extends CalculatedCachedProperties`). A spinoff from uBerscore library. Docs will follow, see the specs till then :-) | ||
* Version 0.1.0 - Compiled on 2015-06-11 19:51:42 | ||
* Version 0.1.1 - Compiled on 2015-06-12 11:01:56 | ||
* Repository git://github.com/anodynos/calculated-cached-properties | ||
@@ -12,2 +12,2 @@ * Copyright(c) 2015 Angelos Pikoulas <agelos.pikoulas@gmail.com> | ||
(function(){var e=!("function"!=typeof define||!define.amd),t="object"==typeof exports;(function(r){var o=function(r,o){return e||t||(r.CalculatedCachedProperties=o),o};if("object"==typeof exports)module.exports=o(global,r(require,exports,module));else if("function"==typeof define&&define.amd)define(["require","exports","module"],function(e,t,n){return o(window,r(e,t,n))});else{var n=function(e){throw new Error("uRequire: Loading UMD module as <script>, failed to `require('"+e+"')`: reason unexpected !")},i={},s={exports:i};o(window,r(n,i,s))}}).call(this,function(e,t,r){var o,n,i=[].slice;return n={extend:function(e,t){var r;for(r in t)e[r]=t[r]},keys:function(e){var t,r;r=[];for(t in e)r.push(t);return r},isFunction:function(e){return"function"==typeof e}},o=function(){function e(){this.defineCalcProperties()}var t,r,o;return o=function(e){return"__$$"+e+"__$$"},r=o("cache"),t={cUndefined:!0},e.register=function(t,r){var o,i,s;return n.isFunction(t)?(o=t,n.extend(o.prototype,e.prototype),n.extend(o.calcProperties||(o.calcProperties={}),r),o.prototype.defineCalcProperties()):(s=t,n.extend(s.__proto__={},e.prototype),s.constructor=i=function(){},i.prototype=s.__proto__,n.extend(i.prototype,e.prototype),n.extend(i.calcProperties||(i.calcProperties={}),r),s.defineCalcProperties()),t},e.prototype.getClasses=function(e,t){return null==t&&(t=[]),e||(e=this),n.isFunction(e)||(e=e.constructor),t.unshift(e),e.__super__?this.getClasses(e.__super__.constructor,t):t},e.getClasses=e.prototype.getClasses,e.prototype.getAllCalcProperties=function(e){var t,r,o,n,i,s,c,l;for(null==e&&(e=this),n={},c=this.getClasses(e),i=0,s=c.length;s>i;i++){t=c[i],l=t.calcProperties;for(o in l)r=l[o],n[o]=r}return n},e.getAllCalcProperties=e.prototype.getAllCalcProperties,Object.defineProperties(e.prototype,{allCalcProperties:{get:function(){return this.constructor.prototype.hasOwnProperty("_allCalcProperties")||Object.defineProperty(this.constructor.prototype,"_allCalcProperties",{value:this.getAllCalcProperties(),enumerable:!1}),this.constructor.prototype._allCalcProperties}},classes:{get:function(){return this.constructor.prototype.hasOwnProperty("_classes")||Object.defineProperty(this.constructor.prototype,"_classes",{value:this.getClasses(),enumerable:!1}),this.constructor.prototype._classes}}}),e.prototype.initCache=function(){var e,o,n;Object.defineProperty(this,r,{value:{},enumerable:!0,configurable:!1,writeable:!1}),n=this.allCalcProperties||this.getAllCalcProperties();for(o in n)e=n[o],this[r][o]=t},e.prototype.defineCalcProperties=function(e){var o,n,i;i=this.allCalcProperties||this.getAllCalcProperties();for(n in i)o=i[n],(!this.constructor.prototype.hasOwnProperty(n)||e)&&!function(e){return function(o,n){return Object.defineProperty(e.constructor.prototype,o,{enumerable:!0,configurable:!0,get:function(){return this[r]||this.initCache(),this[r][o]===t&&(this[r][o]=n.call(this)),this[r][o]},set:function(e){return this[r]||this.initCache(),this[r][o]=e}})}}(this)(n,o);return null},e.prototype.cleanProps=function(){var e,o,s,c,l,p,u,a,f;for(o=1<=arguments.length?i.call(arguments,0):[],0===o.length&&(o=n.keys(this.allCalcProperties||this.getAllCalcProperties())),s=[],p=0,a=o.length;a>p;p++)if(e=o[p])if(n.isFunction(e))for(l||(l=n.keys(this.allCalcProperties||this.getAllCalcProperties())),u=0,f=l.length;f>u;u++)c=l[u],e(c)&&this[r][c]!==t&&(this[r][c]=t,s.push(c));else this[r][e]!==t&&(this[r][e]=t,s.push(e));return s},e}(),r.exports=o,r.exports})}).call(this); | ||
(function(){var e=!("function"!=typeof define||!define.amd),t="object"==typeof exports;(function(r){var o=function(r,o){return e||t||(r.CalculatedCachedProperties=o),o};if("object"==typeof exports)module.exports=o(global,r(require,exports,module));else if("function"==typeof define&&define.amd)define(["require","exports","module"],function(e,t,n){return o(window,r(e,t,n))});else{var n=function(e){throw new Error("uRequire: Loading UMD module as <script>, failed to `require('"+e+"')`: reason unexpected !")},i={},s={exports:i};o(window,r(n,i,s))}}).call(this,function(e,t,r){var o,n,i=[].slice;return n={extend:function(e,t){var r;for(r in t)e[r]=t[r]},keys:function(e){var t,r;r=[];for(t in e)r.push(t);return r},isFunction:function(e){return"function"==typeof e}},o=function(){function e(){this.defineCalcProperties()}var t,r,o;return o=function(e){return"__$$"+e+"__$$"},r=o("cache"),t={cUndefined:!0},e.register=function(t,r,o){var i,s,c;return n.isFunction(t)?(i=t,n.extend(i.prototype,e.prototype),n.extend(i.calcProperties||(i.calcProperties={}),r),i.prototype.defineCalcProperties()):(c=t,n.extend(c.__proto__={},e.prototype),c.constructor=s=function(){},s.prototype=c.__proto__,n.extend(s.prototype,e.prototype),n.extend(s.calcProperties||(s.calcProperties={}),r),c.defineCalcProperties(o)),t},e.prototype.getClasses=function(e,t){return null==t&&(t=[]),e||(e=this),n.isFunction(e)||(e=e.constructor),t.unshift(e),e.__super__?this.getClasses(e.__super__.constructor,t):t},e.getClasses=e.prototype.getClasses,e.prototype.getAllCalcProperties=function(e){var t,r,o,n,i,s,c,l;for(null==e&&(e=this),n={},c=this.getClasses(e),i=0,s=c.length;s>i;i++){t=c[i],l=t.calcProperties;for(o in l)r=l[o],n[o]=r}return n},e.getAllCalcProperties=e.prototype.getAllCalcProperties,Object.defineProperties(e.prototype,{allCalcProperties:{get:function(){return this.constructor.prototype.hasOwnProperty("_allCalcProperties")||Object.defineProperty(this.constructor.prototype,"_allCalcProperties",{value:this.getAllCalcProperties(),enumerable:!1}),this.constructor.prototype._allCalcProperties}},classes:{get:function(){return this.constructor.prototype.hasOwnProperty("_classes")||Object.defineProperty(this.constructor.prototype,"_classes",{value:this.getClasses(),enumerable:!1}),this.constructor.prototype._classes}}}),e.prototype.initCache=function(){var e,o,n;Object.defineProperty(this,r,{value:{},enumerable:!0,configurable:!1,writeable:!1}),n=this.allCalcProperties||this.getAllCalcProperties();for(o in n)e=n[o],this[r][o]=t},e.prototype.defineCalcProperties=function(e){var o,n,i;i=this.allCalcProperties||this.getAllCalcProperties();for(n in i)o=i[n],(!this.constructor.prototype.hasOwnProperty(n)||e)&&!function(e){return function(o,n){return Object.defineProperty(e.constructor.prototype,o,{enumerable:!0,configurable:!0,get:function(){return this[r]||this.initCache(),this[r][o]===t&&(this[r][o]=n.call(this)),this[r][o]},set:function(e){return this[r]||this.initCache(),this[r][o]=e}})}}(this)(n,o);return null},e.prototype.cleanProps=function(){var e,o,s,c,l,p,u,a,f;for(o=1<=arguments.length?i.call(arguments,0):[],0===o.length&&(o=n.keys(this.allCalcProperties||this.getAllCalcProperties())),s=[],p=0,a=o.length;a>p;p++)if(e=o[p])if(n.isFunction(e))for(l||(l=n.keys(this.allCalcProperties||this.getAllCalcProperties())),u=0,f=l.length;f>u;u++)c=l[u],e(c)&&this[r][c]!==t&&(this[r][c]=t,s.push(c));else this[r][e]!==t&&(this[r][e]=t,s.push(e));return s},e}(),r.exports=o,r.exports})}).call(this); |
{ | ||
"name": "calculated-cached-properties", | ||
"description": "CalculatedCachedProperties allows properties to have values calculated by a function, and then cached. You can then manually invalidate the cache for one or more (or all) properties, forcing the function to invoked and recalculate next time the property is accessed. You can also set the value of property manually. Undefined / null etc are all valid property values. Works with POJSOs, JS constructors and CoffeeScript classes (i.e `MyClass extends CalculatedCachedProperties`). A spinoff from uBerscore library. Docs will follow, see the specs till then :-)", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"homepage": "https://github.com/anodynos/calculated-cached-properties", | ||
@@ -34,3 +34,3 @@ "author": { | ||
}, | ||
"main": "./build/dev/CalculatedCachedProperties.js", | ||
"main": "./build/min/CalculatedCachedProperties-min.js", | ||
"scripts": { | ||
@@ -37,0 +37,0 @@ "test": "grunt release" |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
0
21183
7
281
1