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.0.4 to 0.1.0

24

bower.json
{
"name": "calculated-cached-properties",
"version": "0.0.4",
"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",
"main": [
"build/dev/calculated-cached-properties.js",
"build/min/calculated-cached-properties-min.js"
"build/dev/CalculatedCachedProperties.js",
"build/min/CalculatedCachedProperties-min.js"
],

@@ -14,3 +15,2 @@ "ignore": [

"source/spec/*.*",
"source/examples/*.*",
"draft/*",

@@ -22,10 +22,18 @@ "build/spec",

],
"dependencies": {
"lodash": "*"
},
"keywords": [
"calculated",
"cached",
"cache",
"property",
"properties",
"objects",
"constructors",
"coffeescript class"
],
"devDependencies": {
"chai": "*",
"mocha": "*",
"uberscore": "~0.0.16"
"uberscore": "~0.0.16",
"lodash": "*"
}
}
/**
* calculated-cached-properties https://github.com/anodynos/calculated-cached-properties
*
* calculated-cached-properties, a spinoff of uBerscore library. Docs will follow.
* Version 0.0.4 - Compiled on 2015-06-07 18:42:32
* 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
* Repository git://github.com/anodynos/calculated-cached-properties
* Copyright(c) 2015 Agelos Pikoulas <agelos.pikoulas@gmail.com>
* Copyright(c) 2015 Angelos Pikoulas <agelos.pikoulas@gmail.com>
* License MIT http://www.opensource.org/licenses/mit-license.php

@@ -17,7 +17,5 @@ */

__isWeb = !__isNode;
var __slice = [].slice;
(function (factory) {
var rootExport = function (root, __umodule__) {
if (!__isAMD && !__isNode) {root['CCP'] = __umodule__;
if (!__isAMD && !__isNode) {root['CalculatedCachedProperties'] = __umodule__;

@@ -27,25 +25,12 @@ }return __umodule__;

if (typeof exports === 'object') {
module.exports = rootExport(global, factory(require, exports, module, require('lodash')));
} else if (typeof define === 'function' && define.amd) { define(['require', 'exports', 'module', 'lodash'], function (require, exports, module, _) {
return rootExport(window, factory(require, exports, module, _));
module.exports = rootExport(global, factory(require, exports, module));
} else if (typeof define === 'function' && define.amd) { define(['require', 'exports', 'module'], function (require, exports, module) {
return rootExport(window, factory(require, exports, module));
}); } else {
var modNameVars = {'lodash': ["_"]},
_require = function(modyle) {
if (modNameVars[modyle])
for (var _i = 0; _i < modNameVars[modyle].length; _i++)
if (window.hasOwnProperty(modNameVars[modyle][_i]))
return window[modNameVars[modyle][_i]];
var msg = "uRequire: Running UMD module as plain <script>, failed to `require('" + modyle + "')`:";
if (modNameVars[modyle] && modNameVars[modyle].length)
msg = msg + "it`s not exported on `window` as any of these vars: " + JSON.stringify(modNameVars[modyle]);
else
msg = msg + "WITHOUT an AMD or CommonJS loader & " +
"no identifier (i.e varName or param name) associated with dependency '"+modyle+"' in the bundle of 'CalculatedCachedProperties'.";
throw new Error(msg);
}, _exports = {}, _module = {exports: _exports};
rootExport(window, factory(_require, _exports, _module, _));;
var _require = function(modyle){
throw new Error("uRequire: Loading UMD module as <script>, failed to `require('" + modyle + "')`: reason unexpected !");
}, _exports = {}, _module = {exports: _exports};
rootExport(window, factory(_require, _exports, _module));;
}
}).call(this, function (require, exports, module, _) {
}).call(this, function (require, exports, module) {

@@ -55,183 +40,204 @@

var CalculatedCachedProperties;
return CalculatedCachedProperties = function () {
var cUndefined, cacheKey, prefix;
prefix = function (prop) {
return "__$$" + prop + "__$$";
};
cacheKey = prefix("cache");
cUndefined = { "cUndefined": true };
CalculatedCachedProperties.register = function (pojsoOrConstructor, calcProperties) {
var classConstructor, ctor, pojso;
if (_.isFunction(pojsoOrConstructor)) {
classConstructor = pojsoOrConstructor;
_.extend(classConstructor.prototype, CalculatedCachedProperties.prototype);
_.extend(classConstructor.calcProperties || (classConstructor.calcProperties = {}), calcProperties);
classConstructor.prototype.defineCalcProperties();
} else {
pojso = pojsoOrConstructor;
_.extend(pojso.__proto__ = {}, CalculatedCachedProperties.prototype);
pojso.constructor = ctor = function () {
};
ctor.prototype = pojso.__proto__;
_.extend(ctor.prototype, CalculatedCachedProperties.prototype);
_.extend(ctor.calcProperties || (ctor.calcProperties = {}), calcProperties);
pojso.defineCalcProperties();
var CalculatedCachedProperties, _, __slice = [].slice;
_ = {
extend: function (target, source) {
var key;
for (key in source) {
target[key] = source[key];
}
},
keys: function (obj) {
var key, _results;
_results = [];
for (key in obj) {
_results.push(key);
}
return _results;
},
isFunction: function (funct) {
return typeof funct === "function";
}
};
CalculatedCachedProperties = function () {
var cUndefined, cacheKey, prefix;
prefix = function (prop) {
return "__$$" + prop + "__$$";
};
cacheKey = prefix("cache");
cUndefined = { "cUndefined": true };
CalculatedCachedProperties.register = function (pojsoOrConstructor, calcProperties) {
var classConstructor, ctor, pojso;
if (_.isFunction(pojsoOrConstructor)) {
classConstructor = pojsoOrConstructor;
_.extend(classConstructor.prototype, CalculatedCachedProperties.prototype);
_.extend(classConstructor.calcProperties || (classConstructor.calcProperties = {}), calcProperties);
classConstructor.prototype.defineCalcProperties();
} else {
pojso = pojsoOrConstructor;
_.extend(pojso.__proto__ = {}, CalculatedCachedProperties.prototype);
pojso.constructor = ctor = function () {
};
ctor.prototype = pojso.__proto__;
_.extend(ctor.prototype, CalculatedCachedProperties.prototype);
_.extend(ctor.calcProperties || (ctor.calcProperties = {}), calcProperties);
pojso.defineCalcProperties();
}
return pojsoOrConstructor;
};
CalculatedCachedProperties.prototype.getClasses = function (instOrClass, _classes) {
if (_classes == null) {
_classes = [];
}
if (!instOrClass) {
instOrClass = this;
}
if (!_.isFunction(instOrClass)) {
instOrClass = instOrClass.constructor;
}
_classes.unshift(instOrClass);
if (instOrClass.__super__) {
return this.getClasses(instOrClass.__super__.constructor, _classes);
} else {
return _classes;
}
};
CalculatedCachedProperties.getClasses = CalculatedCachedProperties.prototype.getClasses;
CalculatedCachedProperties.prototype.getAllCalcProperties = function (instOrClass) {
var aClass, cFunct, cProp, calcProps, _i, _len, _ref, _ref1;
if (instOrClass == null) {
instOrClass = this;
}
calcProps = {};
_ref = this.getClasses(instOrClass);
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
aClass = _ref[_i];
_ref1 = aClass.calcProperties;
for (cProp in _ref1) {
cFunct = _ref1[cProp];
calcProps[cProp] = cFunct;
}
return pojsoOrConstructor;
};
CalculatedCachedProperties.prototype.getClasses = function (instOrClass, _classes) {
if (_classes == null) {
_classes = [];
}
if (!instOrClass) {
instOrClass = this;
}
if (!_.isFunction(instOrClass)) {
instOrClass = instOrClass.constructor;
}
_classes.unshift(instOrClass);
if (instOrClass.__super__) {
return this.getClasses(instOrClass.__super__.constructor, _classes);
} else {
return _classes;
}
};
CalculatedCachedProperties.getClasses = CalculatedCachedProperties.prototype.getClasses;
CalculatedCachedProperties.prototype.getAllCalcProperties = function (instOrClass) {
var aClass, cFunct, cProp, calcProps, _i, _len, _ref, _ref1;
if (instOrClass == null) {
instOrClass = this;
}
calcProps = {};
_ref = this.getClasses(instOrClass);
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
aClass = _ref[_i];
_ref1 = aClass.calcProperties;
for (cProp in _ref1) {
cFunct = _ref1[cProp];
calcProps[cProp] = cFunct;
}
return calcProps;
};
CalculatedCachedProperties.getAllCalcProperties = CalculatedCachedProperties.prototype.getAllCalcProperties;
Object.defineProperties(CalculatedCachedProperties.prototype, {
allCalcProperties: {
get: function () {
if (!this.constructor.prototype.hasOwnProperty("_allCalcProperties")) {
Object.defineProperty(this.constructor.prototype, "_allCalcProperties", {
value: this.getAllCalcProperties(),
enumerable: false
});
}
return this.constructor.prototype._allCalcProperties;
}
return calcProps;
};
CalculatedCachedProperties.getAllCalcProperties = CalculatedCachedProperties.prototype.getAllCalcProperties;
Object.defineProperties(CalculatedCachedProperties.prototype, {
allCalcProperties: {
get: function () {
if (!this.constructor.prototype.hasOwnProperty("_allCalcProperties")) {
Object.defineProperty(this.constructor.prototype, "_allCalcProperties", {
value: this.getAllCalcProperties(),
enumerable: false
});
}
return this.constructor.prototype._allCalcProperties;
},
classes: {
get: function () {
if (!this.constructor.prototype.hasOwnProperty("_classes")) {
Object.defineProperty(this.constructor.prototype, "_classes", {
value: this.getClasses(),
enumerable: false
});
}
},
classes: {
get: function () {
if (!this.constructor.prototype.hasOwnProperty("_classes")) {
Object.defineProperty(this.constructor.prototype, "_classes", {
value: this.getClasses(),
enumerable: false
});
}
return this.constructor.prototype._classes;
}
return this.constructor.prototype._classes;
}
}
});
function CalculatedCachedProperties() {
this.defineCalcProperties();
}
CalculatedCachedProperties.prototype.initCache = function () {
var cPropFn, cPropName, _ref;
l.deb("Initializing cache for calculated properties of constructor named `" + this.constructor.name + "`");
Object.defineProperty(this, cacheKey, {
value: {},
enumerable: true,
configurable: false,
writeable: false
});
function CalculatedCachedProperties() {
this.defineCalcProperties();
_ref = this.allCalcProperties || this.getAllCalcProperties();
for (cPropName in _ref) {
cPropFn = _ref[cPropName];
this[cacheKey][cPropName] = cUndefined;
}
CalculatedCachedProperties.prototype.initCache = function () {
var cPropFn, cPropName, _ref;
l.deb("Initializing cache for calculated properties of constructor named `" + this.constructor.name + "`");
Object.defineProperty(this, cacheKey, {
value: {},
enumerable: true,
configurable: false,
writeable: false
});
_ref = this.allCalcProperties || this.getAllCalcProperties();
for (cPropName in _ref) {
cPropFn = _ref[cPropName];
this[cacheKey][cPropName] = cUndefined;
}
};
CalculatedCachedProperties.prototype.defineCalcProperties = function (isOverwrite) {
var cPropFn, cPropName, _ref;
_ref = this.allCalcProperties || this.getAllCalcProperties();
for (cPropName in _ref) {
cPropFn = _ref[cPropName];
if (!this.constructor.prototype.hasOwnProperty(cPropName) || isOverwrite) {
(function (_this) {
return function (cPropName, cPropFn) {
l.deb("...defining calculated property " + _this.constructor.name + "." + cPropName);
return Object.defineProperty(_this.constructor.prototype, cPropName, {
enumerable: true,
configurable: true,
get: function () {
if (!this[cacheKey]) {
this.initCache();
}
l.deb("...requesting calculated property " + this.constructor.name + "." + cPropName);
if (this[cacheKey][cPropName] === cUndefined) {
l.deb("...refreshing calculated property " + this.constructor.name + "." + cPropName);
this[cacheKey][cPropName] = cPropFn.call(this);
}
return this[cacheKey][cPropName];
},
set: function (v) {
if (!this[cacheKey]) {
this.initCache();
}
return this[cacheKey][cPropName] = v;
};
CalculatedCachedProperties.prototype.defineCalcProperties = function (isOverwrite) {
var cPropFn, cPropName, _ref;
_ref = this.allCalcProperties || this.getAllCalcProperties();
for (cPropName in _ref) {
cPropFn = _ref[cPropName];
if (!this.constructor.prototype.hasOwnProperty(cPropName) || isOverwrite) {
(function (_this) {
return function (cPropName, cPropFn) {
l.deb("...defining calculated property " + _this.constructor.name + "." + cPropName);
return Object.defineProperty(_this.constructor.prototype, cPropName, {
enumerable: true,
configurable: true,
get: function () {
if (!this[cacheKey]) {
this.initCache();
}
});
};
}(this)(cPropName, cPropFn));
}
}
return null;
};
CalculatedCachedProperties.prototype.cleanProps = function () {
var ca, cleanArgs, cleaned, p, propKeys, _i, _j, _len, _len1;
cleanArgs = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
if (_.isEmpty(cleanArgs)) {
cleanArgs = _.keys(this.allCalcProperties || this.getAllCalcProperties());
}
cleaned = [];
for (_i = 0, _len = cleanArgs.length; _i < _len; _i++) {
ca = cleanArgs[_i];
if (ca) {
if (_.isFunction(ca)) {
if (!propKeys) {
propKeys = _.keys(this.allCalcProperties || this.getAllCalcProperties());
}
for (_j = 0, _len1 = propKeys.length; _j < _len1; _j++) {
p = propKeys[_j];
if (ca(p)) {
if (this[cacheKey][p] !== cUndefined) {
l.deb("...delete (via fn) value of property " + this.constructor.name + "." + p);
this[cacheKey][p] = cUndefined;
cleaned.push(p);
l.deb("...requesting calculated property " + this.constructor.name + "." + cPropName);
if (this[cacheKey][cPropName] === cUndefined) {
l.deb("...refreshing calculated property " + this.constructor.name + "." + cPropName);
this[cacheKey][cPropName] = cPropFn.call(this);
}
return this[cacheKey][cPropName];
},
set: function (v) {
if (!this[cacheKey]) {
this.initCache();
}
return this[cacheKey][cPropName] = v;
}
});
};
}(this)(cPropName, cPropFn));
}
}
return null;
};
CalculatedCachedProperties.prototype.cleanProps = 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());
}
cleaned = [];
for (_i = 0, _len = cleanArgs.length; _i < _len; _i++) {
ca = cleanArgs[_i];
if (ca) {
if (_.isFunction(ca)) {
if (!propKeys) {
propKeys = _.keys(this.allCalcProperties || this.getAllCalcProperties());
}
for (_j = 0, _len1 = propKeys.length; _j < _len1; _j++) {
p = propKeys[_j];
if (ca(p)) {
if (this[cacheKey][p] !== cUndefined) {
l.deb("...delete (via fn) value of property " + this.constructor.name + "." + p);
this[cacheKey][p] = cUndefined;
cleaned.push(p);
}
}
} else {
if (this[cacheKey][ca] !== cUndefined) {
l.deb("...delete value of property " + this.constructor.name + "." + ca);
this[cacheKey][ca] = cUndefined;
cleaned.push(ca);
}
}
} else {
if (this[cacheKey][ca] !== cUndefined) {
l.deb("...delete value of property " + this.constructor.name + "." + ca);
this[cacheKey][ca] = cUndefined;
cleaned.push(ca);
}
}
}
return cleaned;
};
return CalculatedCachedProperties;
}();
}
return cleaned;
};
return CalculatedCachedProperties;
}();
module.exports = CalculatedCachedProperties;
return module.exports;
});
}).call(this);
/**
* calculated-cached-properties https://github.com/anodynos/calculated-cached-properties
*
* calculated-cached-properties, a spinoff of uBerscore library. Docs will follow.
* Version 0.0.4 - Compiled on 2015-06-07 18:42:35
* 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
* Repository git://github.com/anodynos/calculated-cached-properties
* Copyright(c) 2015 Agelos Pikoulas <agelos.pikoulas@gmail.com>
* Copyright(c) 2015 Angelos Pikoulas <agelos.pikoulas@gmail.com>
* License MIT http://www.opensource.org/licenses/mit-license.php
*/
(function(){var e=!("function"!=typeof define||!define.amd),t="object"==typeof exports,r=[].slice;(function(r){var o=function(r,o){return e||t||(r.CCP=o),o};if("object"==typeof exports)module.exports=o(global,r(require,exports,module,require("lodash")));else if("function"==typeof define&&define.amd)define(["require","exports","module","lodash"],function(e,t,i,n){return o(window,r(e,t,i,n))});else{var i={lodash:["_"]},n=function(e){if(i[e])for(var t=0;t<i[e].length;t++)if(window.hasOwnProperty(i[e][t]))return window[i[e][t]];var r="uRequire: Running UMD module as plain <script>, failed to `require('"+e+"')`:";throw r=i[e]&&i[e].length?r+"it`s not exported on `window` as any of these vars: "+JSON.stringify(i[e]):r+"WITHOUT an AMD or CommonJS loader & no identifier (i.e varName or param name) associated with dependency '"+e+"' in the bundle of 'CalculatedCachedProperties'.",new Error(r)},s={},l={exports:s};o(window,r(n,s,l,_))}}).call(this,function(e,t,o,i){var n;return n=function(){function e(){this.defineCalcProperties()}var t,o,n;return n=function(e){return"__$$"+e+"__$$"},o=n("cache"),t={cUndefined:!0},e.register=function(t,r){var o,n,s;return i.isFunction(t)?(o=t,i.extend(o.prototype,e.prototype),i.extend(o.calcProperties||(o.calcProperties={}),r),o.prototype.defineCalcProperties()):(s=t,i.extend(s.__proto__={},e.prototype),s.constructor=n=function(){},n.prototype=s.__proto__,i.extend(n.prototype,e.prototype),i.extend(n.calcProperties||(n.calcProperties={}),r),s.defineCalcProperties()),t},e.prototype.getClasses=function(e,t){return null==t&&(t=[]),e||(e=this),i.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,i,n,s,l,c;for(null==e&&(e=this),i={},l=this.getClasses(e),n=0,s=l.length;s>n;n++){t=l[n],c=t.calcProperties;for(o in c)r=c[o],i[o]=r}return i},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,r,i;Object.defineProperty(this,o,{value:{},enumerable:!0,configurable:!1,writeable:!1}),i=this.allCalcProperties||this.getAllCalcProperties();for(r in i)e=i[r],this[o][r]=t},e.prototype.defineCalcProperties=function(e){var r,i,n;n=this.allCalcProperties||this.getAllCalcProperties();for(i in n)r=n[i],(!this.constructor.prototype.hasOwnProperty(i)||e)&&!function(e){return function(r,i){return Object.defineProperty(e.constructor.prototype,r,{enumerable:!0,configurable:!0,get:function(){return this[o]||this.initCache(),this[o][r]===t&&(this[o][r]=i.call(this)),this[o][r]},set:function(e){return this[o]||this.initCache(),this[o][r]=e}})}}(this)(i,r);return null},e.prototype.cleanProps=function(){var e,n,s,l,c,a,p,u,h;for(n=1<=arguments.length?r.call(arguments,0):[],i.isEmpty(n)&&(n=i.keys(this.allCalcProperties||this.getAllCalcProperties())),s=[],a=0,u=n.length;u>a;a++)if(e=n[a])if(i.isFunction(e))for(c||(c=i.keys(this.allCalcProperties||this.getAllCalcProperties())),p=0,h=c.length;h>p;p++)l=c[p],e(l)&&this[o][l]!==t&&(this[o][l]=t,s.push(l));else this[o][e]!==t&&(this[o][e]=t,s.push(e));return s},e}()})}).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){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);
/**
* calculated-cached-properties https://github.com/anodynos/calculated-cached-properties
*
* calculated-cached-properties, a spinoff of uBerscore library. Docs will follow.
* Version 0.0.4 - Compiled on 2015-06-07 18:42:34
* 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:46:09
* Repository git://github.com/anodynos/calculated-cached-properties
* Copyright(c) 2015 Agelos Pikoulas <agelos.pikoulas@gmail.com>
* Copyright(c) 2015 Angelos Pikoulas <agelos.pikoulas@gmail.com>
* License MIT http://www.opensource.org/licenses/mit-license.php

@@ -29,3 +29,3 @@ */

};
var bundleFactory = function(_, CCP, chai, _B) {
var bundleFactory = function(_, CalculatedCachedProperties, chai, _B) {
/**

@@ -591,3 +591,3 @@ * @license almond 0.3.1 Copyright (c) 2011-2014, The Dojo Foundation All Rights Reserved.

};
describe("CCP:", function () {
describe("CalculatedCachedProperties:", function () {
var CalculatedCachedProperties2, DirtyNumbers, SelfishNumber, allDnProperties;

@@ -600,3 +600,3 @@ CalculatedCachedProperties2 = function (_super) {

return CalculatedCachedProperties2;
}(CCP);
}(CalculatedCachedProperties);
SelfishNumber = function (_super) {

@@ -657,3 +657,3 @@ __extends(SelfishNumber, _super);

return deepEqual(dn.classes, [
CCP,
CalculatedCachedProperties,
CalculatedCachedProperties2,

@@ -666,3 +666,3 @@ SelfishNumber,

return deepEqual(sn.classes, [
CCP,
CalculatedCachedProperties,
CalculatedCachedProperties2,

@@ -707,3 +707,3 @@ SelfishNumber

deepEqual(SelfishNumber.getAllCalcProperties(dn), allDnProperties);
return deepEqual(CCP.getAllCalcProperties(dn), allDnProperties);
return deepEqual(CalculatedCachedProperties.getAllCalcProperties(dn), allDnProperties);
});

@@ -713,8 +713,8 @@ return it("#2", function () {

deepEqual(SelfishNumber.getAllCalcProperties(sn), SelfishNumber.calcProperties);
return deepEqual(CCP.getAllCalcProperties(sn), SelfishNumber.calcProperties);
return deepEqual(CalculatedCachedProperties.getAllCalcProperties(sn), SelfishNumber.calcProperties);
});
});
});
return describe("with class as param:", function () {
describe("called on (any) instance:", function () {
describe("with class as param:", function () {
return describe("called on (any) instance:", function () {
it("#1", function () {

@@ -727,12 +727,12 @@ return deepEqual(sn.getAllCalcProperties(DirtyNumbers), allDnProperties);

});
return describe("called statically (on any class):", function () {
it("#1", function () {
deepEqual(CCP.getAllCalcProperties(DirtyNumbers), allDnProperties);
return deepEqual(SelfishNumber.getAllCalcProperties(DirtyNumbers), allDnProperties);
});
return it("#2", function () {
deepEqual(CCP.getAllCalcProperties(SelfishNumber), SelfishNumber.calcProperties);
return deepEqual(DirtyNumbers.getAllCalcProperties(SelfishNumber), SelfishNumber.calcProperties);
});
});
return describe("called statically (on any class):", function () {
it("#1", function () {
deepEqual(CalculatedCachedProperties.getAllCalcProperties(DirtyNumbers), allDnProperties);
return deepEqual(SelfishNumber.getAllCalcProperties(DirtyNumbers), allDnProperties);
});
return it("#2", function () {
deepEqual(CalculatedCachedProperties.getAllCalcProperties(SelfishNumber), SelfishNumber.calcProperties);
return deepEqual(DirtyNumbers.getAllCalcProperties(SelfishNumber), SelfishNumber.calcProperties);
});
});

@@ -742,7 +742,8 @@ });

describe("POJSO's prototype registering:", function () {
var ObjectDotPrototype, obj;
var ObjectDotPrototype, calcValue, obj;
ObjectDotPrototype = _.clone(Object.prototype, true);
obj = CCP.register({ someProp: 5 }, {
calcValue = { some: "value" };
obj = CalculatedCachedProperties.register({ someProp: 5 }, {
someCalcProperty: function () {
return { some: "value" };
return calcValue;
}

@@ -755,9 +756,16 @@ });

notDeepEqual(obj.__proto__, Object.prototype);
like(CCP.prototype, obj.__proto__);
like(CalculatedCachedProperties.prototype, obj.__proto__);
return ok(_.has(obj.__proto__, "someCalcProperty"));
});
return it("instance is still an Object instance ", function () {
it("instance is still an Object instance ", function () {
tru(_.isObject(obj));
return tru(_B.isHash(obj));
});
it("calulated property has the correct value", function () {
return equal(obj.someCalcProperty, calcValue);
});
return it.skip("object instance is correctly identified as such", function () {
tru(_.isPlainObject(obj));
return tru(obj.constructor === Object);
});
});

@@ -777,3 +785,3 @@ return describe("calculating & caching properties:", function () {

});
CCP.register(DirtyNumbersJSConstructor, allDnProperties);
CalculatedCachedProperties.register(DirtyNumbersJSConstructor, allDnProperties);
_ref = [

@@ -794,3 +802,3 @@ {

title: "POJSO instances",
dn: CCP.register({
dn: CalculatedCachedProperties.register({
setNums: function (x, y) {

@@ -803,3 +811,3 @@ this.x = x;

}, allDnProperties).setNums(3, 4),
dn2: CCP.register({
dn2: CalculatedCachedProperties.register({
setNums: function (x, y) {

@@ -812,3 +820,3 @@ this.x = x;

}, allDnProperties).setNums(5, 6),
dn3: CCP.register({
dn3: CalculatedCachedProperties.register({
setNums: function (x, y) {

@@ -854,4 +862,4 @@ this.x = x;

it("#1", function () {
dn.x = 5;
dn.y = 4;
dn.x = 55;
dn.y = 44;
equal(dn.added, 7);

@@ -865,4 +873,4 @@ equal(dn.added, 7);

return it("#2", function () {
dn2.x = 2;
dn2.y = 3;
dn2.x = 22;
dn2.y = 33;
equal(dn2.added, 11);

@@ -876,2 +884,24 @@ equal(dn2.added, 11);

});
describe("setting value of property manually becomes the cached result", function () {
it("#1", function () {
dn.added = 333;
equal(dn.added, 333);
equal(dn.added, 333);
equal(dn.calcHits.added, 1);
dn.multiplied = 555;
equal(dn.multiplied, 555);
equal(dn.multiplied, 555);
return equal(dn.calcHits.multiplied, 1);
});
return it("#2", function () {
dn2.added = 444;
equal(dn2.added, 444);
equal(dn2.added, 444);
equal(dn2.calcHits.added, 1);
dn2.multiplied = 777;
equal(dn2.multiplied, 777);
equal(dn2.multiplied, 777);
return equal(dn2.calcHits.multiplied, 1);
});
});
describe("clearing cached property value & recalculate 'em:", function () {

@@ -889,4 +919,4 @@ it("clears cached properties by name & recalculates them on demand", function () {

equal(dn.calcHits.multiplied, 1);
equal(dn.multiplied, 12);
equal(dn.multiplied, 12);
equal(dn.multiplied, 555);
equal(dn.multiplied, 555);
return equal(dn.calcHits.multiplied, 1);

@@ -985,3 +1015,3 @@ });

} else {
return bundleFactory((typeof _ !== 'undefined') ? _ : __throwMissing('lodash', '_'), (typeof CCP !== 'undefined') ? CCP : __throwMissing('calculated-cached-properties', 'CCP'), (typeof chai !== 'undefined') ? chai : __throwMissing('chai', 'chai'), (typeof _B !== 'undefined') ? _B : __throwMissing('uberscore', '_B'));
return bundleFactory((typeof _ !== 'undefined') ? _ : __throwMissing('lodash', '_'), (typeof CalculatedCachedProperties !== 'undefined') ? CalculatedCachedProperties : __throwMissing('calculated-cached-properties', 'CalculatedCachedProperties'), (typeof chai !== 'undefined') ? chai : __throwMissing('chai', 'chai'), (typeof _B !== 'undefined') ? _B : __throwMissing('uberscore', '_B'));
}

@@ -988,0 +1018,0 @@ }

{
"name": "calculated-cached-properties",
"description": "calculated-cached-properties, a spinoff of uBerscore library. Docs will follow.",
"version": "0.0.4",
"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",
"homepage": "https://github.com/anodynos/calculated-cached-properties",
"author": {
"name": "Agelos Pikoulas",
"name": "Angelos Pikoulas",
"email": "agelos.pikoulas@gmail.com"

@@ -19,3 +19,8 @@ },

"cached",
"properties"
"cache",
"property",
"properties",
"objects",
"constructors",
"coffeescript class"
],

@@ -30,3 +35,3 @@ "repository": {

},
"main": "./build/dev/calculated-cached-properties-dev.js",
"main": "./build/dev/CalculatedCachedProperties.js",
"scripts": {

@@ -36,11 +41,8 @@ "test": "grunt release"

"engines": {
"node": ">=0.10"
"node": ">=0.8"
},
"dependencies": {
"lodash": "*"
},
"devDependencies": {
"chai": "^1.9.2",
"mocha": "1.x.x",
"coffee-script": "*",
"lodash": "*",
"grunt": "0.4.5",

@@ -47,0 +49,0 @@ "grunt-urequire": "0.7.x",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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