micro-memoize
Advanced tools
Comparing version 1.3.2 to 1.4.0
# micro-memoize CHANGELOG | ||
## 1.4.0 | ||
* Add `options` as second parameter to `onCacheChanged` | ||
## 1.3.2 | ||
@@ -4,0 +8,0 @@ |
@@ -99,3 +99,3 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
var slice = [].slice; | ||
var onCacheChangeNoOp = function onCacheChangeNoOp(cacheIgnored) {}; // eslint-disable-line no-unused-vars | ||
var onCacheChangeNoOp = function onCacheChangeNoOp(cacheIgnored, optionsIgnored) {}; // eslint-disable-line no-unused-vars | ||
@@ -131,2 +131,10 @@ /** | ||
var normalizedOptions = { | ||
isEqual: isEqual, | ||
isPromise: isPromise, | ||
maxSize: maxSize, | ||
onCacheChange: onCacheChange, | ||
transformKey: transformKey | ||
}; | ||
var getKeyIndex = Object(__WEBPACK_IMPORTED_MODULE_0__utils__["a" /* createGetKeyIndex */])(isEqual); | ||
@@ -165,3 +173,3 @@ var getTransformedKey = transformKey ? Object(__WEBPACK_IMPORTED_MODULE_0__utils__["b" /* createGetTransformedKey */])(transformKey) : null; | ||
onCacheChange(cache); | ||
onCacheChange(cache, normalizedOptions); | ||
} else if (keyIndex) { | ||
@@ -171,3 +179,3 @@ Object(__WEBPACK_IMPORTED_MODULE_0__utils__["d" /* orderByLru */])(cache.keys, keyIndex); | ||
onCacheChange(cache); | ||
onCacheChange(cache, normalizedOptions); | ||
} | ||
@@ -203,9 +211,3 @@ | ||
get: function get() { | ||
return { | ||
isEqual: isEqual, | ||
isPromise: isPromise, | ||
maxSize: maxSize, | ||
onCacheChange: onCacheChange, | ||
transformKey: transformKey | ||
}; | ||
return normalizedOptions; | ||
} | ||
@@ -212,0 +214,0 @@ } |
@@ -1,1 +0,1 @@ | ||
!(function(e,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define("memoize",[],n):"object"==typeof exports?exports.memoize=n():e.memoize=n()})("undefined"!=typeof self?self:this,(function(){return (function(e){function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}var t={};return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:r})},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},n.p="",n(n.s=0)})({"./src/index.js":function(e,n,t){"use strict";function r(e,n){function t(){var n=k?k(a.call(arguments)):arguments,t=b(j.keys,n);return~t?t&&(s(j.keys,t),s(j.values,t),g(j)):(j.keys.length>=h&&(j.keys.pop(),j.values.pop()),j.keys.unshift(k?n:a.call(n)),j.values.unshift(e.apply(this,arguments)),d&&f(j,j.keys[0],b),g(j)),j.values[0]}if(e.isMemoized)return e;var r=n||{},o=r.isEqual,p=void 0===o?c:o,v=r.isPromise,d=void 0!==v&&v,y=r.maxSize,h=void 0===y?1:y,m=r.onCacheChange,g=void 0===m?l:m,x=r.transformKey,b=u(p),k=x?i(x):null,j={keys:[],values:[]};return Object.defineProperties(t,{cache:{configurable:!0,get:function(){return j}},cacheSnapshot:{configurable:!0,get:function(){return{keys:[].concat(j.keys),values:[].concat(j.values)}}},isMemoized:{configurable:!0,get:function(){return!0}},options:{configurable:!0,get:function(){return{isEqual:p,isPromise:d,maxSize:h,onCacheChange:g,transformKey:x}}}}),t}Object.defineProperty(n,"__esModule",{value:!0});var o=function(e){return function(n,t){if(n.length!==t.length)return!1;for(var r=0;r<n.length;r++)if(!e(n[r],t[r]))return!1;return!0}},u=function(e){var n=o(e);return function(e,t){for(var r=0;r<e.length;r++)if(n(e[r],t))return r;return-1}},i=function(e){return function(n){var t=e(n);return Array.isArray(t)?t:[t]}},c=function(e,n){return e===n||e!==e&&n!==n},s=function(e,n){if(n){for(var t=e[n],r=n;r--;)e[r+1]=e[r];e[0]=t}},f=function(e,n,t){e.values[0]=e.values[0].catch((function(r){var o=t(e.keys,n);throw~o&&(e.keys.splice(o,1),e.values.splice(o,1)),r}))};n.default=r;var a=[].slice,l=function(e){}},0:function(e,n,t){e.exports=t("./src/index.js")}})})); | ||
!(function(e,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define("memoize",[],n):"object"==typeof exports?exports.memoize=n():e.memoize=n()})("undefined"!=typeof self?self:this,(function(){return (function(e){function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}var t={};return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:r})},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},n.p="",n(n.s=0)})({"./src/index.js":function(e,n,t){"use strict";function r(e,n){function t(){var n=j?j(a.call(arguments)):arguments,t=k(z.keys,n);return~t?t&&(s(z.keys,t),s(z.values,t),g(z,b)):(z.keys.length>=h&&(z.keys.pop(),z.values.pop()),z.keys.unshift(j?n:a.call(n)),z.values.unshift(e.apply(this,arguments)),d&&f(z,z.keys[0],k),g(z,b)),z.values[0]}if(e.isMemoized)return e;var r=n||{},o=r.isEqual,p=void 0===o?c:o,v=r.isPromise,d=void 0!==v&&v,y=r.maxSize,h=void 0===y?1:y,m=r.onCacheChange,g=void 0===m?l:m,x=r.transformKey,b={isEqual:p,isPromise:d,maxSize:h,onCacheChange:g,transformKey:x},k=u(p),j=x?i(x):null,z={keys:[],values:[]};return Object.defineProperties(t,{cache:{configurable:!0,get:function(){return z}},cacheSnapshot:{configurable:!0,get:function(){return{keys:[].concat(z.keys),values:[].concat(z.values)}}},isMemoized:{configurable:!0,get:function(){return!0}},options:{configurable:!0,get:function(){return b}}}),t}Object.defineProperty(n,"__esModule",{value:!0});var o=function(e){return function(n,t){if(n.length!==t.length)return!1;for(var r=0;r<n.length;r++)if(!e(n[r],t[r]))return!1;return!0}},u=function(e){var n=o(e);return function(e,t){for(var r=0;r<e.length;r++)if(n(e[r],t))return r;return-1}},i=function(e){return function(n){var t=e(n);return Array.isArray(t)?t:[t]}},c=function(e,n){return e===n||e!==e&&n!==n},s=function(e,n){if(n){for(var t=e[n],r=n;r--;)e[r+1]=e[r];e[0]=t}},f=function(e,n,t){e.values[0]=e.values[0].catch((function(r){var o=t(e.keys,n);throw~o&&(e.keys.splice(o,1),e.values.splice(o,1)),r}))};n.default=r;var a=[].slice,l=function(e,n){}},0:function(e,n,t){e.exports=t("./src/index.js")}})})); |
@@ -10,3 +10,3 @@ | ||
var slice = [].slice; | ||
var onCacheChangeNoOp = function onCacheChangeNoOp(cacheIgnored) {}; // eslint-disable-line no-unused-vars | ||
var onCacheChangeNoOp = function onCacheChangeNoOp(cacheIgnored, optionsIgnored) {}; // eslint-disable-line no-unused-vars | ||
@@ -42,2 +42,10 @@ /** | ||
var normalizedOptions = { | ||
isEqual: isEqual, | ||
isPromise: isPromise, | ||
maxSize: maxSize, | ||
onCacheChange: onCacheChange, | ||
transformKey: transformKey | ||
}; | ||
var getKeyIndex = createGetKeyIndex(isEqual); | ||
@@ -76,3 +84,3 @@ var getTransformedKey = transformKey ? createGetTransformedKey(transformKey) : null; | ||
onCacheChange(cache); | ||
onCacheChange(cache, normalizedOptions); | ||
} else if (keyIndex) { | ||
@@ -82,3 +90,3 @@ orderByLru(cache.keys, keyIndex); | ||
onCacheChange(cache); | ||
onCacheChange(cache, normalizedOptions); | ||
} | ||
@@ -114,9 +122,3 @@ | ||
get: function get() { | ||
return { | ||
isEqual: isEqual, | ||
isPromise: isPromise, | ||
maxSize: maxSize, | ||
onCacheChange: onCacheChange, | ||
transformKey: transformKey | ||
}; | ||
return normalizedOptions; | ||
} | ||
@@ -123,0 +125,0 @@ } |
@@ -11,3 +11,3 @@ declare module 'micro-memoize' { | ||
maxSize?: number, | ||
onCacheChange?: (cache: Cache) => void, | ||
onCacheChange?: (cache: Cache, options: Options) => void, | ||
transformKey?: (args: any[]) => any | ||
@@ -14,0 +14,0 @@ }; |
@@ -10,3 +10,3 @@ interface Cache = { | ||
maxSize?: number; | ||
onCacheChange?: (cache: Cache) => void; | ||
onCacheChange?: (cache: Cache, options: Options) => void; | ||
transformKey?: (args: any[]) => any; | ||
@@ -13,0 +13,0 @@ } |
@@ -13,3 +13,3 @@ 'use strict'; | ||
var onCacheChangeNoOp = function onCacheChangeNoOp(cacheIgnored) {}; // eslint-disable-line no-unused-vars | ||
var onCacheChangeNoOp = function onCacheChangeNoOp(cacheIgnored, optionsIgnored) {}; // eslint-disable-line no-unused-vars | ||
@@ -45,2 +45,10 @@ /** | ||
var normalizedOptions = { | ||
isEqual: isEqual, | ||
isPromise: isPromise, | ||
maxSize: maxSize, | ||
onCacheChange: onCacheChange, | ||
transformKey: transformKey | ||
}; | ||
var getKeyIndex = (0, _utils.createGetKeyIndex)(isEqual); | ||
@@ -79,3 +87,3 @@ var getTransformedKey = transformKey ? (0, _utils.createGetTransformedKey)(transformKey) : null; | ||
onCacheChange(cache); | ||
onCacheChange(cache, normalizedOptions); | ||
} else if (keyIndex) { | ||
@@ -85,3 +93,3 @@ (0, _utils.orderByLru)(cache.keys, keyIndex); | ||
onCacheChange(cache); | ||
onCacheChange(cache, normalizedOptions); | ||
} | ||
@@ -117,9 +125,3 @@ | ||
get: function get() { | ||
return { | ||
isEqual: isEqual, | ||
isPromise: isPromise, | ||
maxSize: maxSize, | ||
onCacheChange: onCacheChange, | ||
transformKey: transformKey | ||
}; | ||
return normalizedOptions; | ||
} | ||
@@ -126,0 +128,0 @@ } |
@@ -50,3 +50,3 @@ { | ||
"fast-equals": "^1.0.6", | ||
"fast-memoize": "^2.2.8", | ||
"fast-memoize": "^2.3.0", | ||
"flow-babel-webpack-plugin": "^1.1.1", | ||
@@ -73,3 +73,3 @@ "hash-it": "^3.1.2", | ||
"underscore": "^1.8.3", | ||
"webpack": "^3.10.0", | ||
"webpack": "^3.11.0", | ||
"webpack-dev-server": "^2.11.1" | ||
@@ -121,3 +121,3 @@ }, | ||
"types": "./index.d.ts", | ||
"version": "1.3.2" | ||
"version": "1.4.0" | ||
} |
@@ -170,3 +170,3 @@ # micro-memoize | ||
`function(cache: Cache): void`, _defaults to noop_ | ||
`function(cache: Cache, options: Options): void`, _defaults to noop_ | ||
@@ -181,4 +181,5 @@ Callback method that fires whenever the cache is added to or the order is updated. This is mainly to allow for higher-order caching managers that use `micro-memoize` to perform superset functionality on the `cache` object. | ||
const memoized = memoize(fn, { | ||
onCacheChange(cache) { | ||
console.log('cache has changed'); | ||
onCacheChange(cache, options) { | ||
console.log('cache has changed: ', cache); | ||
console.log('memoized method has the following options applied: ', options); | ||
} | ||
@@ -310,12 +311,12 @@ }); | ||
| ----------------- | ------------------- | ------------------------ | | ||
| fast-memoize | 119,718,907 | 0.53% | | ||
| **micro-memoize** | **75,755,597** | **0.95%** | | ||
| moize | 32,458,401 | 1.10% | | ||
| lodash | 26,653,074 | 0.69% | | ||
| underscore | 24,061,584 | 1.29% | | ||
| memoizee | 15,879,536 | 1.20% | | ||
| lru-memoize | 7,741,622 | 1.55% | | ||
| Addy Osmani | 6,404,093 | 0.76% | | ||
| memoizerific | 5,598,961 | 0.72% | | ||
| ramda | 1,049,845 | 0.67% | | ||
| fast-memoize | 216,253,916 | 0.52% | | ||
| **micro-memoize** | **73,773,206** | **0.72%** | | ||
| moize | 32,876,461 | 1.32% | | ||
| lodash | 26,120,451 | 0.63% | | ||
| underscore | 24,182,719 | 0.91% | | ||
| memoizee | 15,985,593 | 0.71% | | ||
| lru-memoize | 8,081,640 | 1.38% | | ||
| Addy Osmani | 6,316,808 | 0.71% | | ||
| memoizerific | 5,575,876 | 0.72% | | ||
| ramda | 1,075,505 | 0.74% | | ||
@@ -328,12 +329,11 @@ #### Single parameter (complex object) | ||
| ----------------- | ------------------- | ------------------------ | | ||
| **micro-memoize** | **59,420,299** | **1.07%** | | ||
| moize | 31,638,535 | 1.28% | | ||
| memoizee | 11,602,462 | 0.91% | | ||
| underscore | 8,008,104 | 0.69% | | ||
| lodash | 7,492,133 | 0.71% | | ||
| lru-memoize | 6,857,335 | 0.76% | | ||
| memoizerific | 4,149,715 | 0.66% | | ||
| Addy Osmani | 1,653,080 | 0.65% | | ||
| fast-memoize | 1,389,359 | 0.63% | | ||
| ramda | 202,891 | 0.92% | | ||
| **micro-memoize** | **57,195,925** | **1.17%** | | ||
| memoizee | 11,602,482 | 0.73% | | ||
| underscore | 7,787,524 | 0.76% | | ||
| lodash | 7,785,492 | 0.58% | | ||
| lru-memoize | 6,839,520 | 0.91% | | ||
| memoizerific | 4,279,061 | 0.67% | | ||
| Addy Osmani | 1,637,983 | 2.07% | | ||
| fast-memoize | 1,392,560 | 0.59% | | ||
| ramda | 213,542 | 0.78% | | ||
@@ -346,9 +346,8 @@ #### Multiple parameters (primitives only) | ||
| ----------------- | ------------------- | ------------------------ | | ||
| **micro-memoize** | **48,688,157** | **0.97%** | | ||
| moize | 24,249,539 | 0.97% | | ||
| memoizee | 10,475,078 | 1.27% | | ||
| lru-memoize | 6,283,782 | 1.22% | | ||
| memoizerific | 4,335,184 | 0.57% | | ||
| Addy Osmani | 3,089,544 | 0.64% | | ||
| fast-memoize | 1,136,783 | 0.71% | | ||
| **micro-memoize** | **47,354,287** | **0.73%** | | ||
| memoizee | 10,021,023 | 0.69% | | ||
| lru-memoize | 6,312,064 | 0.75% | | ||
| memoizerific | 4,545,738 | 0.92% | | ||
| Addy Osmani | 3,282,267 | 0.63% | | ||
| fast-memoize | 1,178,468 | 0.70% | | ||
@@ -361,9 +360,8 @@ #### Multiple parameters (complex objects) | ||
| ----------------- | ------------------- | ------------------------ | | ||
| **micro-memoize** | **47,746,243** | **0.69%** | | ||
| moize | 23,651,406 | 1.07% | | ||
| memoizee | 7,285,213 | 0.82% | | ||
| lru-memoize | 6,249,360 | 0.75% | | ||
| memoizerific | 3,376,969 | 0.55% | | ||
| Addy Osmani | 901,307 | 0.78% | | ||
| fast-memoize | 752,356 | 0.57% | | ||
| **micro-memoize** | **46,643,491** | **0.76%** | | ||
| memoizee | 7,270,755 | 0.71% | | ||
| lru-memoize | 6,292,754 | 0.84% | | ||
| memoizerific | 3,427,550 | 0.78% | | ||
| Addy Osmani | 926,721 | 0.67% | | ||
| fast-memoize | 783,907 | 0.79% | | ||
@@ -370,0 +368,0 @@ ## Browser support |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
318247
1183
393