micro-memoize
Advanced tools
Comparing version 2.1.0 to 2.1.1
# micro-memoize CHANGELOG | ||
## 2.1.1 | ||
- Upgrade to babel 7 | ||
- Add `"sideEffects": false` for better tree-shaking with webpack | ||
## 2.1.0 | ||
@@ -4,0 +9,0 @@ |
@@ -7,2 +7,19 @@ (function (global, factory) { | ||
function _objectWithoutPropertiesLoose(source, excluded) { | ||
if (source == null) return {}; | ||
var target = {}; | ||
var sourceKeys = Object.keys(source); | ||
var key, i; | ||
for (i = 0; i < sourceKeys.length; i++) { | ||
key = sourceKeys[i]; | ||
if (excluded.indexOf(key) >= 0) continue; | ||
target[key] = source[key]; | ||
} | ||
return target; | ||
} | ||
// types | ||
/** | ||
@@ -26,6 +43,2 @@ * @function cloneArray | ||
}; | ||
// types | ||
var createAreKeysEqual = function createAreKeysEqual(isEqual | ||
@@ -57,6 +70,4 @@ /** | ||
}; | ||
var createGetKeyIndex = function createGetKeyIndex(isEqual, isMatchingKey) { | ||
var areKeysEqual = typeof isMatchingKey === 'function' ? isMatchingKey : createAreKeysEqual(isEqual); | ||
/** | ||
@@ -73,2 +84,3 @@ * @function getKeyIndex | ||
*/ | ||
return function (allKeys, keysToMatch) { | ||
@@ -84,3 +96,2 @@ for (var index = 0; index < allKeys.length; index++) { | ||
}; | ||
/** | ||
@@ -96,7 +107,8 @@ * @function isSameValueZero | ||
*/ | ||
var isSameValueZero = function isSameValueZero(object1, object2) { | ||
return object1 === object2 || object1 !== object1 && object2 !== object2; | ||
}; | ||
/* eslint-disable no-unused-vars */ | ||
/* eslint-disable no-unused-vars */ | ||
var onCacheOperation = function onCacheOperation(cacheIgnored, optionsIgnored, memoized) {}; | ||
@@ -115,2 +127,3 @@ /* eslint-enable */ | ||
*/ | ||
var orderByLru = function orderByLru(array, value, startingIndex) { | ||
@@ -125,3 +138,2 @@ var index = startingIndex; | ||
}; | ||
/** | ||
@@ -137,9 +149,8 @@ * @function setPromiseHandler | ||
*/ | ||
var setPromiseHandler = function setPromiseHandler(cache, options, memoized) { | ||
var key = cache.keys[0]; | ||
cache.values[0] = cache.values[0].then(function (value) { | ||
options.onCacheHit(cache, options, memoized); | ||
options.onCacheChange(cache, options, memoized); | ||
return value; | ||
@@ -158,4 +169,2 @@ }).catch(function (error) { | ||
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } | ||
/** | ||
@@ -174,4 +183,2 @@ * @function memoize | ||
// types | ||
function memoize(fn, options) { | ||
@@ -185,16 +192,16 @@ // if it is a memoized method, don't re-memoize it | ||
_ref$isEqual = _ref.isEqual, | ||
isEqual = _ref$isEqual === undefined ? isSameValueZero : _ref$isEqual, | ||
isEqual = _ref$isEqual === void 0 ? isSameValueZero : _ref$isEqual, | ||
isMatchingKey = _ref.isMatchingKey, | ||
_ref$isPromise = _ref.isPromise, | ||
isPromise = _ref$isPromise === undefined ? false : _ref$isPromise, | ||
isPromise = _ref$isPromise === void 0 ? false : _ref$isPromise, | ||
_ref$maxSize = _ref.maxSize, | ||
maxSize = _ref$maxSize === undefined ? 1 : _ref$maxSize, | ||
maxSize = _ref$maxSize === void 0 ? 1 : _ref$maxSize, | ||
_ref$onCacheAdd = _ref.onCacheAdd, | ||
onCacheAdd = _ref$onCacheAdd === undefined ? onCacheOperation : _ref$onCacheAdd, | ||
onCacheAdd = _ref$onCacheAdd === void 0 ? onCacheOperation : _ref$onCacheAdd, | ||
_ref$onCacheChange = _ref.onCacheChange, | ||
onCacheChange = _ref$onCacheChange === undefined ? onCacheOperation : _ref$onCacheChange, | ||
onCacheChange = _ref$onCacheChange === void 0 ? onCacheOperation : _ref$onCacheChange, | ||
_ref$onCacheHit = _ref.onCacheHit, | ||
onCacheHit = _ref$onCacheHit === undefined ? onCacheOperation : _ref$onCacheHit, | ||
onCacheHit = _ref$onCacheHit === void 0 ? onCacheOperation : _ref$onCacheHit, | ||
transformKey = _ref.transformKey, | ||
extraOptions = _objectWithoutProperties(_ref, ['isEqual', 'isMatchingKey', 'isPromise', 'maxSize', 'onCacheAdd', 'onCacheChange', 'onCacheHit', 'transformKey']); | ||
extraOptions = _objectWithoutPropertiesLoose(_ref, ["isEqual", "isMatchingKey", "isPromise", "maxSize", "onCacheAdd", "onCacheChange", "onCacheHit", "transformKey"]); | ||
@@ -211,11 +218,11 @@ var normalizedOptions = Object.assign({}, extraOptions, { | ||
}); | ||
var getKeyIndex = createGetKeyIndex(isEqual, isMatchingKey); | ||
var shouldCloneArguments = !!(transformKey || isMatchingKey); | ||
var cache = { | ||
keys: [], | ||
get size() { | ||
return cache.keys.length; | ||
}, | ||
values: [] | ||
@@ -225,3 +232,2 @@ }; | ||
values = cache.values; | ||
/** | ||
@@ -248,3 +254,2 @@ * @function memoized | ||
orderByLru(values, values[keyIndex], keyIndex); | ||
onCacheChange(cache, normalizedOptions, memoized); | ||
@@ -260,3 +265,2 @@ } | ||
var newValue = fn.apply(this, arguments); | ||
orderByLru(keys, newKey, keys.length); | ||
@@ -306,3 +310,2 @@ orderByLru(values, newValue, values.length); | ||
}); | ||
return memoized; | ||
@@ -309,0 +312,0 @@ } |
@@ -1,1 +0,1 @@ | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n(e.memoize={})}(this,function(e){"use strict";var M=function(e){for(var n=new Array(e.length),t=0;t<e.length;t++)n[t]=e[t];return n},O=function(e,n){var i,r="function"==typeof n?n:(i=e,function(e,n){if(e.length!==n.length)return!1;for(var t=0;t<e.length;t++)if(!i(e[t],n[t]))return!1;return!0});return function(e,n){for(var t=0;t<e.length;t++)if(r(e[t],n))return t;return-1}},P=function(e,n){return e===n||e!=e&&n!=n},j=function(e,n,t){},q=function(e,n,t){for(var i=t;i--;)e[i+1]=e[i];e[0]=n};e.default=function(s,e){if(s.isMemoized)return s;var n=e||{},t=n.isEqual,i=void 0===t?P:t,r=n.isMatchingKey,o=n.isPromise,f=void 0!==o&&o,a=n.maxSize,h=void 0===a?1:a,u=n.onCacheAdd,l=void 0===u?j:u,c=n.onCacheChange,g=void 0===c?j:c,d=n.onCacheHit,v=void 0===d?j:d,y=n.transformKey,p=function(e,n){var t={};for(var i in e)0<=n.indexOf(i)||Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}(n,["isEqual","isMatchingKey","isPromise","maxSize","onCacheAdd","onCacheChange","onCacheHit","transformKey"]),m=Object.assign({},p,{isEqual:i,isMatchingKey:r,isPromise:f,maxSize:h,onCacheAdd:l,onCacheChange:g,onCacheHit:v,transformKey:y}),C=O(i,r),b=!(!y&&!r),z={keys:[],get size(){return z.keys.length},values:[]},k=z.keys,x=z.values;function K(){var t,i,n,r,e=b?M(arguments):arguments,o=y?y(e):e,a=C(k,o);if(~a)v(z,m,K),a&&(q(k,k[a],a),q(x,x[a],a),g(z,m,K));else{k.length>=h&&(k.pop(),x.pop());var u=b?o:M(e),c=s.apply(this,arguments);q(k,u,k.length),q(x,c,x.length),f&&(i=m,n=K,r=(t=z).keys[0],t.values[0]=t.values[0].then(function(e){return i.onCacheHit(t,i,n),i.onCacheChange(t,i,n),e}).catch(function(e){var n=O(i.isEqual)(t.keys,r);throw~n&&(t.keys.splice(n,1),t.values.splice(n,1)),e})),l(z,m,K),g(z,m,K)}return x[0]}return Object.defineProperties(K,{cache:{configurable:!0,get:function(){return z}},cacheSnapshot:{configurable:!0,get:function(){return{keys:M(z.keys),size:z.size,values:M(z.values)}}},isMemoized:{configurable:!0,get:function(){return!0}},options:{configurable:!0,get:function(){return m}}}),K},Object.defineProperty(e,"__esModule",{value:!0})}); | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n(e.memoize={})}(this,function(e){"use strict";var M=function(e){for(var n=new Array(e.length),t=0;t<e.length;t++)n[t]=e[t];return n},j=function(e,n){var i,r="function"==typeof n?n:(i=e,function(e,n){if(e.length!==n.length)return!1;for(var t=0;t<e.length;t++)if(!i(e[t],n[t]))return!1;return!0});return function(e,n){for(var t=0;t<e.length;t++)if(r(e[t],n))return t;return-1}},O=function(e,n){return e===n||e!=e&&n!=n},P=function(e,n,t){},q=function(e,n,t){for(var i=t;i--;)e[i+1]=e[i];e[0]=n};e.default=function(c,e){if(c.isMemoized)return c;var n=e||{},t=n.isEqual,i=void 0===t?O:t,r=n.isMatchingKey,o=n.isPromise,f=void 0!==o&&o,u=n.maxSize,h=void 0===u?1:u,a=n.onCacheAdd,l=void 0===a?P:a,s=n.onCacheChange,g=void 0===s?P:s,d=n.onCacheHit,v=void 0===d?P:d,y=n.transformKey,p=function(e,n){if(null==e)return{};var t,i,r={},o=Object.keys(e);for(i=0;i<o.length;i++)t=o[i],0<=n.indexOf(t)||(r[t]=e[t]);return r}(n,["isEqual","isMatchingKey","isPromise","maxSize","onCacheAdd","onCacheChange","onCacheHit","transformKey"]),m=Object.assign({},p,{isEqual:i,isMatchingKey:r,isPromise:f,maxSize:h,onCacheAdd:l,onCacheChange:g,onCacheHit:v,transformKey:y}),C=j(i,r),b=!(!y&&!r),k={keys:[],get size(){return k.keys.length},values:[]},z=k.keys,x=k.values;function K(){var t,i,n,r,e=b?M(arguments):arguments,o=y?y(e):e,u=C(z,o);if(~u)v(k,m,K),u&&(q(z,z[u],u),q(x,x[u],u),g(k,m,K));else{z.length>=h&&(z.pop(),x.pop());var a=b?o:M(e),s=c.apply(this,arguments);q(z,a,z.length),q(x,s,x.length),f&&(i=m,n=K,r=(t=k).keys[0],t.values[0]=t.values[0].then(function(e){return i.onCacheHit(t,i,n),i.onCacheChange(t,i,n),e}).catch(function(e){var n=j(i.isEqual)(t.keys,r);throw~n&&(t.keys.splice(n,1),t.values.splice(n,1)),e})),l(k,m,K),g(k,m,K)}return x[0]}return Object.defineProperties(K,{cache:{configurable:!0,get:function(){return k}},cacheSnapshot:{configurable:!0,get:function(){return{keys:M(k.keys),size:k.size,values:M(k.values)}}},isMemoized:{configurable:!0,get:function(){return!0}},options:{configurable:!0,get:function(){return m}}}),K},Object.defineProperty(e,"__esModule",{value:!0})}); |
@@ -1,6 +0,6 @@ | ||
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } | ||
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; } | ||
// types | ||
// utils | ||
import { cloneArray, createGetKeyIndex, isSameValueZero, onCacheOperation, orderByLru, setPromiseHandler } from './utils'; | ||
/** | ||
@@ -19,4 +19,2 @@ * @function memoize | ||
// types | ||
export default function memoize(fn, options) { | ||
@@ -30,16 +28,16 @@ // if it is a memoized method, don't re-memoize it | ||
_ref$isEqual = _ref.isEqual, | ||
isEqual = _ref$isEqual === undefined ? isSameValueZero : _ref$isEqual, | ||
isEqual = _ref$isEqual === void 0 ? isSameValueZero : _ref$isEqual, | ||
isMatchingKey = _ref.isMatchingKey, | ||
_ref$isPromise = _ref.isPromise, | ||
isPromise = _ref$isPromise === undefined ? false : _ref$isPromise, | ||
isPromise = _ref$isPromise === void 0 ? false : _ref$isPromise, | ||
_ref$maxSize = _ref.maxSize, | ||
maxSize = _ref$maxSize === undefined ? 1 : _ref$maxSize, | ||
maxSize = _ref$maxSize === void 0 ? 1 : _ref$maxSize, | ||
_ref$onCacheAdd = _ref.onCacheAdd, | ||
onCacheAdd = _ref$onCacheAdd === undefined ? onCacheOperation : _ref$onCacheAdd, | ||
onCacheAdd = _ref$onCacheAdd === void 0 ? onCacheOperation : _ref$onCacheAdd, | ||
_ref$onCacheChange = _ref.onCacheChange, | ||
onCacheChange = _ref$onCacheChange === undefined ? onCacheOperation : _ref$onCacheChange, | ||
onCacheChange = _ref$onCacheChange === void 0 ? onCacheOperation : _ref$onCacheChange, | ||
_ref$onCacheHit = _ref.onCacheHit, | ||
onCacheHit = _ref$onCacheHit === undefined ? onCacheOperation : _ref$onCacheHit, | ||
onCacheHit = _ref$onCacheHit === void 0 ? onCacheOperation : _ref$onCacheHit, | ||
transformKey = _ref.transformKey, | ||
extraOptions = _objectWithoutProperties(_ref, ['isEqual', 'isMatchingKey', 'isPromise', 'maxSize', 'onCacheAdd', 'onCacheChange', 'onCacheHit', 'transformKey']); | ||
extraOptions = _objectWithoutPropertiesLoose(_ref, ["isEqual", "isMatchingKey", "isPromise", "maxSize", "onCacheAdd", "onCacheChange", "onCacheHit", "transformKey"]); | ||
@@ -56,11 +54,11 @@ var normalizedOptions = Object.assign({}, extraOptions, { | ||
}); | ||
var getKeyIndex = createGetKeyIndex(isEqual, isMatchingKey); | ||
var shouldCloneArguments = !!(transformKey || isMatchingKey); | ||
var cache = { | ||
keys: [], | ||
get size() { | ||
return cache.keys.length; | ||
}, | ||
values: [] | ||
@@ -70,3 +68,2 @@ }; | ||
values = cache.values; | ||
/** | ||
@@ -93,3 +90,2 @@ * @function memoized | ||
orderByLru(values, values[keyIndex], keyIndex); | ||
onCacheChange(cache, normalizedOptions, memoized); | ||
@@ -105,3 +101,2 @@ } | ||
var newValue = fn.apply(this, arguments); | ||
orderByLru(keys, newKey, keys.length); | ||
@@ -151,4 +146,3 @@ orderByLru(values, newValue, values.length); | ||
}); | ||
return memoized; | ||
} |
@@ -0,3 +1,3 @@ | ||
// types | ||
/** | ||
@@ -21,6 +21,2 @@ * @function cloneArray | ||
}; | ||
// types | ||
export var createAreKeysEqual = function createAreKeysEqual(isEqual | ||
@@ -52,6 +48,4 @@ /** | ||
}; | ||
export var createGetKeyIndex = function createGetKeyIndex(isEqual, isMatchingKey) { | ||
var areKeysEqual = typeof isMatchingKey === 'function' ? isMatchingKey : createAreKeysEqual(isEqual); | ||
/** | ||
@@ -68,2 +62,3 @@ * @function getKeyIndex | ||
*/ | ||
return function (allKeys, keysToMatch) { | ||
@@ -79,3 +74,2 @@ for (var index = 0; index < allKeys.length; index++) { | ||
}; | ||
/** | ||
@@ -91,7 +85,8 @@ * @function isSameValueZero | ||
*/ | ||
export var isSameValueZero = function isSameValueZero(object1, object2) { | ||
return object1 === object2 || object1 !== object1 && object2 !== object2; | ||
}; | ||
/* eslint-disable no-unused-vars */ | ||
/* eslint-disable no-unused-vars */ | ||
export var onCacheOperation = function onCacheOperation(cacheIgnored, optionsIgnored, memoized) {}; | ||
@@ -110,2 +105,3 @@ /* eslint-enable */ | ||
*/ | ||
export var orderByLru = function orderByLru(array, value, startingIndex) { | ||
@@ -120,3 +116,2 @@ var index = startingIndex; | ||
}; | ||
/** | ||
@@ -132,9 +127,8 @@ * @function setPromiseHandler | ||
*/ | ||
export var setPromiseHandler = function setPromiseHandler(cache, options, memoized) { | ||
var key = cache.keys[0]; | ||
cache.values[0] = cache.values[0].then(function (value) { | ||
options.onCacheHit(cache, options, memoized); | ||
options.onCacheChange(cache, options, memoized); | ||
return value; | ||
@@ -141,0 +135,0 @@ }).catch(function (error) { |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -6,9 +6,6 @@ exports.__esModule = true; | ||
var _utils = require('./utils'); | ||
var _utils = require("./utils"); | ||
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } | ||
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; } | ||
// utils | ||
/** | ||
@@ -26,5 +23,2 @@ * @function memoize | ||
*/ | ||
// types | ||
function memoize(fn, options) { | ||
@@ -38,16 +32,16 @@ // if it is a memoized method, don't re-memoize it | ||
_ref$isEqual = _ref.isEqual, | ||
isEqual = _ref$isEqual === undefined ? _utils.isSameValueZero : _ref$isEqual, | ||
isEqual = _ref$isEqual === void 0 ? _utils.isSameValueZero : _ref$isEqual, | ||
isMatchingKey = _ref.isMatchingKey, | ||
_ref$isPromise = _ref.isPromise, | ||
isPromise = _ref$isPromise === undefined ? false : _ref$isPromise, | ||
isPromise = _ref$isPromise === void 0 ? false : _ref$isPromise, | ||
_ref$maxSize = _ref.maxSize, | ||
maxSize = _ref$maxSize === undefined ? 1 : _ref$maxSize, | ||
maxSize = _ref$maxSize === void 0 ? 1 : _ref$maxSize, | ||
_ref$onCacheAdd = _ref.onCacheAdd, | ||
onCacheAdd = _ref$onCacheAdd === undefined ? _utils.onCacheOperation : _ref$onCacheAdd, | ||
onCacheAdd = _ref$onCacheAdd === void 0 ? _utils.onCacheOperation : _ref$onCacheAdd, | ||
_ref$onCacheChange = _ref.onCacheChange, | ||
onCacheChange = _ref$onCacheChange === undefined ? _utils.onCacheOperation : _ref$onCacheChange, | ||
onCacheChange = _ref$onCacheChange === void 0 ? _utils.onCacheOperation : _ref$onCacheChange, | ||
_ref$onCacheHit = _ref.onCacheHit, | ||
onCacheHit = _ref$onCacheHit === undefined ? _utils.onCacheOperation : _ref$onCacheHit, | ||
onCacheHit = _ref$onCacheHit === void 0 ? _utils.onCacheOperation : _ref$onCacheHit, | ||
transformKey = _ref.transformKey, | ||
extraOptions = _objectWithoutProperties(_ref, ['isEqual', 'isMatchingKey', 'isPromise', 'maxSize', 'onCacheAdd', 'onCacheChange', 'onCacheHit', 'transformKey']); | ||
extraOptions = _objectWithoutPropertiesLoose(_ref, ["isEqual", "isMatchingKey", "isPromise", "maxSize", "onCacheAdd", "onCacheChange", "onCacheHit", "transformKey"]); | ||
@@ -64,11 +58,11 @@ var normalizedOptions = Object.assign({}, extraOptions, { | ||
}); | ||
var getKeyIndex = (0, _utils.createGetKeyIndex)(isEqual, isMatchingKey); | ||
var shouldCloneArguments = !!(transformKey || isMatchingKey); | ||
var cache = { | ||
keys: [], | ||
get size() { | ||
return cache.keys.length; | ||
}, | ||
values: [] | ||
@@ -78,3 +72,2 @@ }; | ||
values = cache.values; | ||
/** | ||
@@ -101,3 +94,2 @@ * @function memoized | ||
(0, _utils.orderByLru)(values, values[keyIndex], keyIndex); | ||
onCacheChange(cache, normalizedOptions, memoized); | ||
@@ -113,3 +105,2 @@ } | ||
var newValue = fn.apply(this, arguments); | ||
(0, _utils.orderByLru)(keys, newKey, keys.length); | ||
@@ -159,4 +150,3 @@ (0, _utils.orderByLru)(values, newValue, values.length); | ||
}); | ||
return memoized; | ||
} |
@@ -1,5 +0,7 @@ | ||
'use strict'; | ||
"use strict"; | ||
exports.__esModule = true; | ||
exports.setPromiseHandler = exports.orderByLru = exports.onCacheOperation = exports.isSameValueZero = exports.createGetKeyIndex = exports.createAreKeysEqual = exports.cloneArray = void 0; | ||
// types | ||
@@ -15,3 +17,3 @@ /** | ||
*/ | ||
var cloneArray = exports.cloneArray = function cloneArray(arrayLike) { | ||
var cloneArray = function cloneArray(arrayLike) { | ||
var array = new Array(arrayLike.length); | ||
@@ -26,4 +28,5 @@ | ||
// types | ||
var createAreKeysEqual = exports.createAreKeysEqual = function createAreKeysEqual(isEqual | ||
exports.cloneArray = cloneArray; | ||
var createAreKeysEqual = function createAreKeysEqual(isEqual | ||
/** | ||
@@ -55,5 +58,6 @@ * @function areKeysEqual | ||
var createGetKeyIndex = exports.createGetKeyIndex = function createGetKeyIndex(isEqual, isMatchingKey) { | ||
exports.createAreKeysEqual = createAreKeysEqual; | ||
var createGetKeyIndex = function createGetKeyIndex(isEqual, isMatchingKey) { | ||
var areKeysEqual = typeof isMatchingKey === 'function' ? isMatchingKey : createAreKeysEqual(isEqual); | ||
/** | ||
@@ -70,2 +74,3 @@ * @function getKeyIndex | ||
*/ | ||
return function (allKeys, keysToMatch) { | ||
@@ -81,3 +86,2 @@ for (var index = 0; index < allKeys.length; index++) { | ||
}; | ||
/** | ||
@@ -93,8 +97,15 @@ * @function isSameValueZero | ||
*/ | ||
var isSameValueZero = exports.isSameValueZero = function isSameValueZero(object1, object2) { | ||
exports.createGetKeyIndex = createGetKeyIndex; | ||
var isSameValueZero = function isSameValueZero(object1, object2) { | ||
return object1 === object2 || object1 !== object1 && object2 !== object2; | ||
}; | ||
/* eslint-disable no-unused-vars */ | ||
/* eslint-disable no-unused-vars */ | ||
var onCacheOperation = exports.onCacheOperation = function onCacheOperation(cacheIgnored, optionsIgnored, memoized) {}; | ||
exports.isSameValueZero = isSameValueZero; | ||
var onCacheOperation = function onCacheOperation(cacheIgnored, optionsIgnored, memoized) {}; | ||
/* eslint-enable */ | ||
@@ -112,3 +123,7 @@ | ||
*/ | ||
var orderByLru = exports.orderByLru = function orderByLru(array, value, startingIndex) { | ||
exports.onCacheOperation = onCacheOperation; | ||
var orderByLru = function orderByLru(array, value, startingIndex) { | ||
var index = startingIndex; | ||
@@ -122,3 +137,2 @@ | ||
}; | ||
/** | ||
@@ -134,9 +148,11 @@ * @function setPromiseHandler | ||
*/ | ||
var setPromiseHandler = exports.setPromiseHandler = function setPromiseHandler(cache, options, memoized) { | ||
exports.orderByLru = orderByLru; | ||
var setPromiseHandler = function setPromiseHandler(cache, options, memoized) { | ||
var key = cache.keys[0]; | ||
cache.values[0] = cache.values[0].then(function (value) { | ||
options.onCacheHit(cache, options, memoized); | ||
options.onCacheChange(cache, options, memoized); | ||
return value; | ||
@@ -153,2 +169,4 @@ }).catch(function (error) { | ||
}); | ||
}; | ||
}; | ||
exports.setPromiseHandler = setPromiseHandler; |
{ | ||
"author": "tony.quetano@planttheidea.com", | ||
"ava": { | ||
"babel": "inherit", | ||
"failFast": true, | ||
@@ -10,5 +9,5 @@ "files": [ | ||
"require": [ | ||
"babel-register" | ||
"@babel/register" | ||
], | ||
"source": [ | ||
"sources": [ | ||
"src/*.js" | ||
@@ -31,14 +30,15 @@ ], | ||
"devDependencies": { | ||
"ava": "^0.25.0", | ||
"babel-cli": "^6.26.0", | ||
"babel-core": "^6.26.3", | ||
"babel-eslint": "^8.2.6", | ||
"babel-loader": "^7.1.5", | ||
"babel-plugin-syntax-flow": "^6.18.0", | ||
"babel-plugin-transform-flow-strip-types": "^6.22.0", | ||
"babel-plugin-transform-runtime": "^6.23.0", | ||
"babel-preset-env": "^1.7.0", | ||
"babel-preset-react": "^6.24.1", | ||
"babel-preset-stage-2": "^6.24.1", | ||
"babel-register": "^6.26.0", | ||
"@babel/cli": "^7.0.0", | ||
"@babel/core": "^7.0.0", | ||
"@babel/plugin-syntax-flow": "^7.0.0", | ||
"@babel/plugin-transform-flow-strip-types": "^7.0.0", | ||
"@babel/plugin-transform-runtime": "^7.0.0", | ||
"@babel/preset-env": "^7.0.0", | ||
"@babel/preset-flow": "^7.0.0", | ||
"@babel/preset-react": "^7.0.0", | ||
"@babel/register": "^7.0.0", | ||
"@babel/runtime": "^7.0.0", | ||
"ava": "^1.0.0-beta.8", | ||
"babel-eslint": "^9.0.0", | ||
"babel-loader": "^8.0.0", | ||
"benchmark": "^2.1.4", | ||
@@ -60,6 +60,6 @@ "case-sensitive-paths-webpack-plugin": "^2.1.2", | ||
"lru-memoize": "^1.0.2", | ||
"mem": "^3.0.1", | ||
"mem": "^4.0.0", | ||
"memoizee": "^0.4.13", | ||
"memoizerific": "^1.11.3", | ||
"nyc": "^12.0.2", | ||
"nyc": "^13.0.1", | ||
"optimize-js-plugin": "^0.0.4", | ||
@@ -74,5 +74,5 @@ "ora": "^3.0.0", | ||
"rimraf": "^2.6.2", | ||
"rollup": "^0.64.1", | ||
"rollup-plugin-babel": "^3.0.7", | ||
"rollup-plugin-uglify": "^4.0.0", | ||
"rollup": "^0.66.0", | ||
"rollup-plugin-babel": "^4.0.1", | ||
"rollup-plugin-uglify": "^6.0.0", | ||
"sinon": "^6.1.5", | ||
@@ -129,4 +129,5 @@ "underscore": "^1.9.1", | ||
}, | ||
"sideEffects": false, | ||
"types": "./index.d.ts", | ||
"version": "2.1.0" | ||
"version": "2.1.1" | ||
} |
@@ -35,3 +35,3 @@ # micro-memoize | ||
As the author of [`moize`](https://github.com/planttheidea/moize), I created a consistently fast memoization library, but `moize` has a lot of features to satisfy a large number of edge cases. `micro-memoize` is a simpler approach, focusing on the core feature set with a much smaller footprint (~1.1kB minified+gzipped). Stripping out these edge cases also allows `micro-memoize` to be faster across the board than `moize`. | ||
As the author of [`moize`](https://github.com/planttheidea/moize), I created a consistently fast memoization library, but `moize` has a lot of features to satisfy a large number of edge cases. `micro-memoize` is a simpler approach, focusing on the core feature set with a much smaller footprint (~1.0kB minified+gzipped). Stripping out these edge cases also allows `micro-memoize` to be faster across the board than `moize`. | ||
@@ -38,0 +38,0 @@ ## Importing |
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
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
1785
652564
50