react-lazy-cache
Advanced tools
Comparing version 2.1.2 to 3.0.0
@@ -63,3 +63,3 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
var _lazyCache = __webpack_require__(2); | ||
var _lazyCache = __webpack_require__(1); | ||
@@ -73,21 +73,2 @@ var _lazyCache2 = _interopRequireDefault(_lazyCache); | ||
/* 1 */ | ||
/***/ function(module, exports) { | ||
'use strict'; | ||
exports.__esModule = true; | ||
exports['default'] = getParamNames; | ||
var stripComments = /(\/\/.*$)|(\/\*[\s\S]*?\*\/)|(\s*=[^,\)]*(('(?:\\'|[^'\r\n])*')|("(?:\\"|[^"\r\n])*"))|(\s*=[^,\)]*))/mg; | ||
var argNames = /([^\s,]+)/g; | ||
function getParamNames(fn) { | ||
var fnStr = fn.toString().replace(stripComments, ''); | ||
var result = fnStr.slice(fnStr.indexOf('(') + 1, fnStr.indexOf(')')).match(argNames); | ||
return result || []; | ||
} | ||
module.exports = exports['default']; | ||
/***/ }, | ||
/* 2 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
@@ -102,8 +83,4 @@ | ||
var _getParamNames = __webpack_require__(1); | ||
var _deepEqual = __webpack_require__(2); | ||
var _getParamNames2 = _interopRequireDefault(_getParamNames); | ||
var _deepEqual = __webpack_require__(3); | ||
var _deepEqual2 = _interopRequireDefault(_deepEqual); | ||
@@ -125,4 +102,4 @@ | ||
Object.keys(calculators).forEach(function (key) { | ||
var calculate = calculators[key]; | ||
var props = _getParamNames2['default'](calculate); | ||
var fn = calculators[key].fn; | ||
var props = calculators[key].params; | ||
props.forEach(function (param) { | ||
@@ -143,3 +120,3 @@ if (! ~allProps.indexOf(param)) { | ||
}); | ||
var value = calculate.apply(undefined, params); | ||
var value = fn.apply(undefined, params); | ||
cache[key] = { props: props, value: value }; | ||
@@ -165,8 +142,8 @@ return value; | ||
/***/ }, | ||
/* 3 */ | ||
/* 2 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
var pSlice = Array.prototype.slice; | ||
var objectKeys = __webpack_require__(5); | ||
var isArguments = __webpack_require__(4); | ||
var objectKeys = __webpack_require__(4); | ||
var isArguments = __webpack_require__(3); | ||
@@ -266,3 +243,3 @@ var deepEqual = module.exports = function (actual, expected, opts) { | ||
/***/ }, | ||
/* 4 */ | ||
/* 3 */ | ||
/***/ function(module, exports) { | ||
@@ -293,3 +270,3 @@ | ||
/***/ }, | ||
/* 5 */ | ||
/* 4 */ | ||
/***/ function(module, exports) { | ||
@@ -296,0 +273,0 @@ |
@@ -1,1 +0,1 @@ | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.ReactLazyCache=e():t.ReactLazyCache=e()}(this,function(){return function(t){function e(n){if(r[n])return r[n].exports;var o=r[n]={exports:{},id:n,loaded:!1};return t[n].call(o.exports,o,o.exports,e),o.loaded=!0,o.exports}var r={};return e.m=t,e.c=r,e.p="",e(0)}([function(t,e,r){"use strict";function n(t){return t&&t.__esModule?t:{"default":t}}e.__esModule=!0;var o=r(2),u=n(o);e.default=u.default,t.exports=e.default},function(t,e){"use strict";function r(t){var e=t.toString().replace(n,""),r=e.slice(e.indexOf("(")+1,e.indexOf(")")).match(o);return r||[]}e.__esModule=!0,e.default=r;var n=/(\/\/.*$)|(\/\*[\s\S]*?\*\/)|(\s*=[^,\)]*(('(?:\\'|[^'\r\n])*')|("(?:\\"|[^"\r\n])*"))|(\s*=[^,\)]*))/gm,o=/([^\s,]+)/g;t.exports=e.default},function(t,e,r){"use strict";function n(t){return t&&t.__esModule?t:{"default":t}}function o(t,e){var r=[],n={},o={},u=function c(t){Object.keys(n).forEach(function(e){~n[e].props.indexOf(t)&&(delete n[e].value,c(e))})};return Object.keys(e).forEach(function(u){var c=e[u],i=f.default(c);i.forEach(function(t){~r.indexOf(t)||r.push(t)}),n[u]={props:i},Object.defineProperty(o,u,{get:function(){var e=n[u];if(e&&void 0!==e.value)return e.value;var r=i.map(function(e){return t.props[e]||o[e]}),f=c.apply(void 0,r);return n[u]={props:i,value:f},f}})}),o.componentWillReceiveProps=function(e){var n=[];r.forEach(function(r){i.default(t.props[r],e[r])||n.push(r)}),n.forEach(u)},o}e.__esModule=!0,e.default=o;var u=r(1),f=n(u),c=r(3),i=n(c);t.exports=e.default},function(t,e,r){function n(t){return null===t||void 0===t}function o(t){return t&&"object"==typeof t&&"number"==typeof t.length?"function"!=typeof t.copy||"function"!=typeof t.slice?!1:t.length>0&&"number"!=typeof t[0]?!1:!0:!1}function u(t,e,r){var u,a;if(n(t)||n(e))return!1;if(t.prototype!==e.prototype)return!1;if(i(t))return i(e)?(t=f.call(t),e=f.call(e),p(t,e,r)):!1;if(o(t)){if(!o(e))return!1;if(t.length!==e.length)return!1;for(u=0;u<t.length;u++)if(t[u]!==e[u])return!1;return!0}try{var l=c(t),s=c(e)}catch(d){return!1}if(l.length!=s.length)return!1;for(l.sort(),s.sort(),u=l.length-1;u>=0;u--)if(l[u]!=s[u])return!1;for(u=l.length-1;u>=0;u--)if(a=l[u],!p(t[a],e[a],r))return!1;return typeof t==typeof e}var f=Array.prototype.slice,c=r(5),i=r(4),p=t.exports=function(t,e,r){return r||(r={}),t===e?!0:t instanceof Date&&e instanceof Date?t.getTime()===e.getTime():!t||!e||"object"!=typeof t&&"object"!=typeof e?r.strict?t===e:t==e:u(t,e,r)}},function(t,e){function r(t){return"[object Arguments]"==Object.prototype.toString.call(t)}function n(t){return t&&"object"==typeof t&&"number"==typeof t.length&&Object.prototype.hasOwnProperty.call(t,"callee")&&!Object.prototype.propertyIsEnumerable.call(t,"callee")||!1}var o="[object Arguments]"==function(){return Object.prototype.toString.call(arguments)}();e=t.exports=o?r:n,e.supported=r,e.unsupported=n},function(t,e){function r(t){var e=[];for(var r in t)e.push(r);return e}e=t.exports="function"==typeof Object.keys?Object.keys:r,e.shim=r}])}); | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.ReactLazyCache=e():t.ReactLazyCache=e()}(this,function(){return function(t){function e(n){if(r[n])return r[n].exports;var o=r[n]={exports:{},id:n,loaded:!1};return t[n].call(o.exports,o,o.exports,e),o.loaded=!0,o.exports}var r={};return e.m=t,e.c=r,e.p="",e(0)}([function(t,e,r){"use strict";function n(t){return t&&t.__esModule?t:{"default":t}}e.__esModule=!0;var o=r(1),u=n(o);e.default=u.default,t.exports=e.default},function(t,e,r){"use strict";function n(t){return t&&t.__esModule?t:{"default":t}}function o(t,e){var r=[],n={},o={},u=function c(t){Object.keys(n).forEach(function(e){~n[e].props.indexOf(t)&&(delete n[e].value,c(e))})};return Object.keys(e).forEach(function(u){var f=e[u].fn,c=e[u].params;c.forEach(function(t){~r.indexOf(t)||r.push(t)}),n[u]={props:c},Object.defineProperty(o,u,{get:function(){var e=n[u];if(e&&void 0!==e.value)return e.value;var r=c.map(function(e){return t.props[e]||o[e]}),p=f.apply(void 0,r);return n[u]={props:c,value:p},p}})}),o.componentWillReceiveProps=function(e){var n=[];r.forEach(function(r){f.default(t.props[r],e[r])||n.push(r)}),n.forEach(u)},o}e.__esModule=!0,e.default=o;var u=r(2),f=n(u);t.exports=e.default},function(t,e,r){function n(t){return null===t||void 0===t}function o(t){return t&&"object"==typeof t&&"number"==typeof t.length?"function"!=typeof t.copy||"function"!=typeof t.slice?!1:t.length>0&&"number"!=typeof t[0]?!1:!0:!1}function u(t,e,r){var u,a;if(n(t)||n(e))return!1;if(t.prototype!==e.prototype)return!1;if(p(t))return p(e)?(t=f.call(t),e=f.call(e),i(t,e,r)):!1;if(o(t)){if(!o(e))return!1;if(t.length!==e.length)return!1;for(u=0;u<t.length;u++)if(t[u]!==e[u])return!1;return!0}try{var l=c(t),s=c(e)}catch(y){return!1}if(l.length!=s.length)return!1;for(l.sort(),s.sort(),u=l.length-1;u>=0;u--)if(l[u]!=s[u])return!1;for(u=l.length-1;u>=0;u--)if(a=l[u],!i(t[a],e[a],r))return!1;return typeof t==typeof e}var f=Array.prototype.slice,c=r(4),p=r(3),i=t.exports=function(t,e,r){return r||(r={}),t===e?!0:t instanceof Date&&e instanceof Date?t.getTime()===e.getTime():!t||!e||"object"!=typeof t&&"object"!=typeof e?r.strict?t===e:t==e:u(t,e,r)}},function(t,e){function r(t){return"[object Arguments]"==Object.prototype.toString.call(t)}function n(t){return t&&"object"==typeof t&&"number"==typeof t.length&&Object.prototype.hasOwnProperty.call(t,"callee")&&!Object.prototype.propertyIsEnumerable.call(t,"callee")||!1}var o="[object Arguments]"==function(){return Object.prototype.toString.call(arguments)}();e=t.exports=o?r:n,e.supported=r,e.unsupported=n},function(t,e){function r(t){var e=[];for(var r in t)e.push(r);return e}e=t.exports="function"==typeof Object.keys?Object.keys:r,e.shim=r}])}); |
@@ -8,6 +8,2 @@ 'use strict'; | ||
var _getParamNames = require('./getParamNames'); | ||
var _getParamNames2 = _interopRequireDefault(_getParamNames); | ||
var _deepEqual = require('deep-equal'); | ||
@@ -31,4 +27,4 @@ | ||
Object.keys(calculators).forEach(function (key) { | ||
var calculate = calculators[key]; | ||
var props = _getParamNames2['default'](calculate); | ||
var fn = calculators[key].fn; | ||
var props = calculators[key].params; | ||
props.forEach(function (param) { | ||
@@ -49,3 +45,3 @@ if (! ~allProps.indexOf(param)) { | ||
}); | ||
var value = calculate.apply(undefined, params); | ||
var value = fn.apply(undefined, params); | ||
cache[key] = { props: props, value: value }; | ||
@@ -52,0 +48,0 @@ return value; |
{ | ||
"name": "react-lazy-cache", | ||
"description": "A utility to lazily calculate and cache values in a react component based on props", | ||
"version": "2.1.2", | ||
"version": "3.0.0", | ||
"homepage": "https://github.com/erikras/react-lazy-cache", | ||
@@ -6,0 +6,0 @@ "repository": { |
@@ -41,7 +41,22 @@ #react-lazy-cache | ||
this.cache = lazyCache(this, { | ||
sum: (a, b) => a + b, | ||
difference: (a, b) => a - b, | ||
product: (a, b) => a * b, | ||
quotient: (a, b) => a / b, | ||
sumSquared: (sum) => sum * sum | ||
sum: { | ||
params: ['a', 'b'], | ||
fn: (a, b) => a + b | ||
}, | ||
difference: { | ||
params: ['a', 'b'], | ||
fn: (a, b) => a - b | ||
}, | ||
product: { | ||
params: ['a', 'b'], | ||
fn: (a, b) => a * b | ||
}, | ||
quotient: { | ||
params: ['a', 'b'], | ||
fn: (a, b) => a / b | ||
}, | ||
sumSquared: { | ||
params: ['sum'], | ||
fn: (sum) => sum * sum | ||
} | ||
}); | ||
@@ -63,3 +78,2 @@ } | ||
</div>); | ||
</div>); | ||
} | ||
@@ -77,9 +91,8 @@ } | ||
### Parameter Injection | ||
### Selecting Parameters | ||
"_But how does it know which prop to use??_", you ask? `react-lazy-cache` detects the names of the props by the | ||
parameter names to the calculation functions. | ||
When you specify your functions to calculate each value, you must specify the `params`, which refer either to props | ||
given to your React component, _or_ to other calculated values (see: `sumSquared`). | ||
You can even inject other calculated values, such as in the case of `sumSquared`. **Be careful to not cause an | ||
infinite dependency loop!** | ||
**Be careful to not cause an infinite dependency loop!** | ||
@@ -86,0 +99,0 @@ ## Conclusion |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
100
18879
7
291