Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

calculated-cached-properties

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

calculated-cached-properties - npm Package Compare versions

Comparing version 0.1.1 to 0.2.0

137

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.1 - Compiled on 2015-06-12 11:01:51
* Version 0.2.0 - Compiled on 2015-06-15 00:01:30
* Repository git://github.com/anodynos/calculated-cached-properties

@@ -12,3 +12,3 @@ * Copyright(c) 2015 Angelos Pikoulas <agelos.pikoulas@gmail.com>

// Generated by uRequire v0.7.0-beta.16 target: 'dev' template: 'UMDplain'
// Generated by uRequire v0.7.0-beta.17 target: 'dev' template: 'UMDplain'
(function () {

@@ -38,3 +38,3 @@

var l = console; l.deb = l.log
var VERSION = '0.2.0'; // injected by urequire-rc-inject-version

@@ -49,2 +49,10 @@ var CalculatedCachedProperties, _, __slice = [].slice;

},
defaults: function (target, source) {
var key;
for (key in source) {
if (!target.hasOwnProperty(key)) {
target[key] = source[key];
}
}
},
keys: function (obj) {

@@ -58,4 +66,4 @@ var key, _results;

},
isFunction: function (funct) {
return typeof funct === "function";
isFunction: function (f) {
return typeof f === "function";
}

@@ -65,14 +73,21 @@ };

var cUndefined, cacheKey, prefix;
CalculatedCachedProperties.VERSION = VERSION;
prefix = function (prop) {
return "__$$" + prop + "__$$";
return "__$$_CCP_" + prop;
};
cacheKey = prefix("cache");
cUndefined = { "cUndefined": true };
CalculatedCachedProperties.register = function (pojsoOrConstructor, calcProperties, isOverwrite) {
cUndefined = { "CalculatedCachedProperties Undefined": true };
CalculatedCachedProperties.register = function (pojsoOrConstructor, calcProperties, options) {
var classConstructor, ctor, pojso;
if (options == null) {
options = CalculatedCachedProperties.optionsDefaults;
}
if (options !== CalculatedCachedProperties.optionsDefaults) {
_.defaults(options || (options = {}), CalculatedCachedProperties.optionsDefaults);
}
if (_.isFunction(pojsoOrConstructor)) {
classConstructor = pojsoOrConstructor;
_.extend(classConstructor.prototype, CalculatedCachedProperties.prototype);
_.extend(classConstructor.calcProperties || (classConstructor.calcProperties = {}), calcProperties);
classConstructor.prototype.defineCalcProperties();
_.extend(classConstructor.CCP_calcProperties || (classConstructor.CCP_calcProperties = {}), calcProperties);
classConstructor.prototype._CCP_defineCalcProperties(options);
} else {

@@ -85,8 +100,8 @@ pojso = pojsoOrConstructor;

_.extend(ctor.prototype, CalculatedCachedProperties.prototype);
_.extend(ctor.calcProperties || (ctor.calcProperties = {}), calcProperties);
pojso.defineCalcProperties(isOverwrite);
_.extend(ctor.CCP_calcProperties || (ctor.CCP_calcProperties = {}), calcProperties);
pojso._CCP_defineCalcProperties(options);
}
return pojsoOrConstructor;
};
CalculatedCachedProperties.prototype.getClasses = function (instOrClass, _classes) {
CalculatedCachedProperties.prototype.CCP_getClasses = function (instOrClass, _classes) {
if (_classes == null) {

@@ -103,3 +118,3 @@ _classes = [];

if (instOrClass.__super__) {
return this.getClasses(instOrClass.__super__.constructor, _classes);
return this.CCP_getClasses(instOrClass.__super__.constructor, _classes);
} else {

@@ -109,4 +124,4 @@ return _classes;

};
CalculatedCachedProperties.getClasses = CalculatedCachedProperties.prototype.getClasses;
CalculatedCachedProperties.prototype.getAllCalcProperties = function (instOrClass) {
CalculatedCachedProperties.CCP_getClasses = CalculatedCachedProperties.prototype.CCP_getClasses;
CalculatedCachedProperties.prototype.CCP_getAllCalcProperties = function (instOrClass) {
var aClass, cFunct, cProp, calcProps, _i, _len, _ref, _ref1;

@@ -117,6 +132,6 @@ if (instOrClass == null) {

calcProps = {};
_ref = this.getClasses(instOrClass);
_ref = this.CCP_getClasses(instOrClass);
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
aClass = _ref[_i];
_ref1 = aClass.calcProperties;
_ref1 = aClass.CCP_calcProperties;
for (cProp in _ref1) {

@@ -129,9 +144,9 @@ cFunct = _ref1[cProp];

};
CalculatedCachedProperties.getAllCalcProperties = CalculatedCachedProperties.prototype.getAllCalcProperties;
CalculatedCachedProperties.CCP_getAllCalcProperties = CalculatedCachedProperties.prototype.CCP_getAllCalcProperties;
Object.defineProperties(CalculatedCachedProperties.prototype, {
allCalcProperties: {
CCP_allCalcProperties: {
get: function () {
if (!this.constructor.prototype.hasOwnProperty("_allCalcProperties")) {
Object.defineProperty(this.constructor.prototype, "_allCalcProperties", {
value: this.getAllCalcProperties(),
value: this.CCP_getAllCalcProperties(),
enumerable: false

@@ -143,7 +158,7 @@ });

},
classes: {
CCP_classes: {
get: function () {
if (!this.constructor.prototype.hasOwnProperty("_classes")) {
Object.defineProperty(this.constructor.prototype, "_classes", {
value: this.getClasses(),
value: this.CCP_getClasses(),
enumerable: false

@@ -156,8 +171,10 @@ });

});
function CalculatedCachedProperties() {
this.defineCalcProperties();
function CalculatedCachedProperties(options) {
this._CCP_defineCalcProperties(options);
}
CalculatedCachedProperties.prototype.initCache = function () {
CalculatedCachedProperties.prototype._CCP_initCache = function () {
var cPropFn, cPropName, _ref;
l.deb("CalculatedCachedProperties: Initializing cache for calculated properties of constructor named `" + this.constructor.name + "`");
if (this.constructor.isDebug(30)) {
console.log("CalculatedCachedProperties: Initializing cache for calculated properties of constructor named `" + (this.constructor.name || "UNNAMED") + "`");
}
Object.defineProperty(this, cacheKey, {

@@ -169,3 +186,3 @@ value: {},

});
_ref = this.allCalcProperties || this.getAllCalcProperties();
_ref = this.CCP_allCalcProperties || this.CCP_getAllCalcProperties();
for (cPropName in _ref) {

@@ -176,11 +193,19 @@ cPropFn = _ref[cPropName];

};
CalculatedCachedProperties.prototype.defineCalcProperties = function (isOverwrite) {
CalculatedCachedProperties.prototype._CCP_defineCalcProperties = function (options) {
var cPropFn, cPropName, _ref;
_ref = this.allCalcProperties || this.getAllCalcProperties();
this.constructor.isDebug = function (lev) {
return options.debugLevel >= lev;
};
if (this.constructor.isDebug(10)) {
console.log("CalculatedCachedProperties: options {} for " + (this.constructor.name || "UNNAMED"), options);
}
_ref = this.CCP_allCalcProperties || this.CCP_getAllCalcProperties();
for (cPropName in _ref) {
cPropFn = _ref[cPropName];
if (!this.constructor.prototype.hasOwnProperty(cPropName) || isOverwrite) {
if (!this.constructor.prototype.hasOwnProperty(cPropName) || options.isOverwrite) {
(function (_this) {
return function (cPropName, cPropFn) {
l.deb("CalculatedCachedProperties: DEFINE calculated property " + _this.constructor.name + "." + cPropName);
if (_this.constructor.isDebug(20)) {
console.log("CalculatedCachedProperties: DEFINE calculated property " + (_this.constructor.name || "UNNAMED") + "." + cPropName);
}
return Object.defineProperty(_this.constructor.prototype, cPropName, {

@@ -190,10 +215,21 @@ enumerable: true,

get: function () {
var result;
if (!this[cacheKey]) {
this.initCache();
this._CCP_initCache();
}
l.deb("CalculatedCachedProperties: GET value of calculated property " + this.constructor.name + "." + cPropName);
if (this[cacheKey][cPropName] === cUndefined) {
l.deb("CalculatedCachedProperties: CALCULATING & CACHING property " + this.constructor.name + "." + cPropName);
this[cacheKey][cPropName] = cPropFn.call(this);
if (this.constructor.isDebug(40)) {
console.log("CalculatedCachedProperties: CALCULATING & CACHING property " + (this.constructor.name || "UNNAMED") + "." + cPropName);
}
result = cPropFn.call(this);
if (this.constructor.isDebug(80)) {
if (!this.constructor.isDebug(1000)) {
console.log("CalculatedCachedProperties: calculated value of " + (this.constructor.name || "UNNAMED") + "." + cPropName + " :", result);
}
}
this[cacheKey][cPropName] = result;
}
if (this.constructor.isDebug(100)) {
console.log("CalculatedCachedProperties: GET value of calculated property " + (this.constructor.name || "UNNAMED") + "." + cPropName, this.constructor.isDebug(1000) ? this[cacheKey][cPropName] : "");
}
return this[cacheKey][cPropName];

@@ -203,5 +239,7 @@ },

if (!this[cacheKey]) {
this.initCache();
this._CCP_initCache();
}
l.deb("CalculatedCachedProperties: SET value of property " + this.constructor.name + "." + cPropName);
if (this.constructor.isDebug(50)) {
console.log("CalculatedCachedProperties: SET value of property " + (this.constructor.name || "UNNAMED") + "." + cPropName);
}
return this[cacheKey][cPropName] = v;

@@ -214,9 +252,8 @@ }

}
return null;
};
CalculatedCachedProperties.prototype.cleanProps = function () {
CalculatedCachedProperties.prototype.CCP_clean = function () {
var ca, cleanArgs, cleaned, p, propKeys, _i, _j, _len, _len1;
cleanArgs = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
if (cleanArgs.length === 0) {
cleanArgs = _.keys(this.allCalcProperties || this.getAllCalcProperties());
cleanArgs = _.keys(this.CCP_allCalcProperties || this.CCP_getAllCalcProperties());
}

@@ -229,3 +266,3 @@ cleaned = [];

if (!propKeys) {
propKeys = _.keys(this.allCalcProperties || this.getAllCalcProperties());
propKeys = _.keys(this.CCP_allCalcProperties || this.CCP_getAllCalcProperties());
}

@@ -236,3 +273,5 @@ for (_j = 0, _len1 = propKeys.length; _j < _len1; _j++) {

if (this[cacheKey][p] !== cUndefined) {
l.deb("CalculatedCachedProperties: CLEAR (via function) value of property " + this.constructor.name + "." + p);
if (this.constructor.isDebug(60)) {
console.log("CalculatedCachedProperties: CLEAN (via function) value of property " + (this.constructor.name || "UNNAMED") + "." + p);
}
this[cacheKey][p] = cUndefined;

@@ -244,7 +283,7 @@ cleaned.push(p);

} else {
if (this[cacheKey][ca] !== cUndefined) {
l.deb("CalculatedCachedProperties: CLEAR value of property " + this.constructor.name + "." + ca);
this[cacheKey][ca] = cUndefined;
cleaned.push(ca);
if (this.constructor.isDebug(60)) {
console.log("CalculatedCachedProperties: CLEAN value of property " + (this.constructor.name || "UNNAMED") + "." + ca);
}
this[cacheKey][ca] = cUndefined;
cleaned.push(ca);
}

@@ -257,2 +296,6 @@ }

}();
CalculatedCachedProperties.optionsDefaults = {
isOverwrite: false,
debugLevel: 0
};
module.exports = CalculatedCachedProperties;

@@ -259,0 +302,0 @@

@@ -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.1 - Compiled on 2015-06-12 11:01:56
* Version 0.2.0 - Compiled on 2015-06-15 00:01:33
* 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,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);
(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,i){return o(window,r(e,t,i))});else{var i=function(e){throw new Error("uRequire: Loading UMD module as <script>, failed to `require('"+e+"')`: reason unexpected !")},n={},s={exports:n};o(window,r(i,n,s))}}).call(this,function(e,t,r){var o,i,n="0.2.0",s=[].slice;return i={extend:function(e,t){var r;for(r in t)e[r]=t[r]},defaults:function(e,t){var r;for(r in t)e.hasOwnProperty(r)||(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(e){this._CCP_defineCalcProperties(e)}var t,r,o;return e.VERSION=n,o=function(e){return"__$$_CCP_"+e},r=o("cache"),t={"CalculatedCachedProperties Undefined":!0},e.register=function(t,r,o){var n,s,l;return null==o&&(o=e.optionsDefaults),o!==e.optionsDefaults&&i.defaults(o||(o={}),e.optionsDefaults),i.isFunction(t)?(n=t,i.extend(n.prototype,e.prototype),i.extend(n.CCP_calcProperties||(n.CCP_calcProperties={}),r),n.prototype._CCP_defineCalcProperties(o)):(l=t,i.extend(l.__proto__={},e.prototype),l.constructor=s=function(){},s.prototype=l.__proto__,i.extend(s.prototype,e.prototype),i.extend(s.CCP_calcProperties||(s.CCP_calcProperties={}),r),l._CCP_defineCalcProperties(o)),t},e.prototype.CCP_getClasses=function(e,t){return null==t&&(t=[]),e||(e=this),i.isFunction(e)||(e=e.constructor),t.unshift(e),e.__super__?this.CCP_getClasses(e.__super__.constructor,t):t},e.CCP_getClasses=e.prototype.CCP_getClasses,e.prototype.CCP_getAllCalcProperties=function(e){var t,r,o,i,n,s,l,c;for(null==e&&(e=this),i={},l=this.CCP_getClasses(e),n=0,s=l.length;s>n;n++){t=l[n],c=t.CCP_calcProperties;for(o in c)r=c[o],i[o]=r}return i},e.CCP_getAllCalcProperties=e.prototype.CCP_getAllCalcProperties,Object.defineProperties(e.prototype,{CCP_allCalcProperties:{get:function(){return this.constructor.prototype.hasOwnProperty("_allCalcProperties")||Object.defineProperty(this.constructor.prototype,"_allCalcProperties",{value:this.CCP_getAllCalcProperties(),enumerable:!1}),this.constructor.prototype._allCalcProperties}},CCP_classes:{get:function(){return this.constructor.prototype.hasOwnProperty("_classes")||Object.defineProperty(this.constructor.prototype,"_classes",{value:this.CCP_getClasses(),enumerable:!1}),this.constructor.prototype._classes}}}),e.prototype._CCP_initCache=function(){var e,o,i;Object.defineProperty(this,r,{value:{},enumerable:!0,configurable:!1,writeable:!1}),i=this.CCP_allCalcProperties||this.CCP_getAllCalcProperties();for(o in i)e=i[o],this[r][o]=t},e.prototype._CCP_defineCalcProperties=function(e){var o,i,n;this.constructor.isDebug=function(t){return e.debugLevel>=t},n=this.CCP_allCalcProperties||this.CCP_getAllCalcProperties();for(i in n)o=n[i],(!this.constructor.prototype.hasOwnProperty(i)||e.isOverwrite)&&!function(e){return function(o,i){return Object.defineProperty(e.constructor.prototype,o,{enumerable:!0,configurable:!0,get:function(){var e;return this[r]||this._CCP_initCache(),this[r][o]===t&&(e=i.call(this),this[r][o]=e),this[r][o]},set:function(e){return this[r]||this._CCP_initCache(),this[r][o]=e}})}}(this)(i,o)},e.prototype.CCP_clean=function(){var e,o,n,l,c,p,u,a,C;for(o=1<=arguments.length?s.call(arguments,0):[],0===o.length&&(o=i.keys(this.CCP_allCalcProperties||this.CCP_getAllCalcProperties())),n=[],p=0,a=o.length;a>p;p++)if(e=o[p])if(i.isFunction(e))for(c||(c=i.keys(this.CCP_allCalcProperties||this.CCP_getAllCalcProperties())),u=0,C=c.length;C>u;u++)l=c[u],e(l)&&this[r][l]!==t&&(this[r][l]=t,n.push(l));else this[r][e]=t,n.push(e);return n},e}(),o.optionsDefaults={isOverwrite:!1,debugLevel:0},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.1",
"version": "0.2.0",
"homepage": "https://github.com/anodynos/calculated-cached-properties",

@@ -48,3 +48,3 @@ "author": {

"grunt-contrib-watch": "0.5.x",
"urequire": ">=0.7.0-beta.16",
"urequire": ">=0.7.0-beta.17",
"urequire-rc-inject-version": "^0.1.5",

@@ -51,0 +51,0 @@ "urequire-rc-import-keys": "^0.1.3",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc