memoize-one
Advanced tools
Comparing version 5.2.0 to 5.2.1
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
var safeIsNaN = Number.isNaN || | ||
@@ -53,3 +51,2 @@ function ponyfill(value) { | ||
exports.default = memoizeOne; | ||
exports.memoizeOne = memoizeOne; | ||
module.exports = memoizeOne; |
export declare type EqualityFn = (newArgs: any[], lastArgs: any[]) => boolean; | ||
declare function memoizeOne<ResultFn extends (this: any, ...newArgs: any[]) => ReturnType<ResultFn>>(resultFn: ResultFn, isEqual?: EqualityFn): ResultFn; | ||
export default memoizeOne; | ||
export { memoizeOne }; |
@@ -50,2 +50,1 @@ var safeIsNaN = Number.isNaN || | ||
export default memoizeOne; | ||
export { memoizeOne }; |
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | ||
typeof define === 'function' && define.amd ? define(['exports'], factory) : | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.memoizeOne = {})); | ||
}(this, (function (exports) { 'use strict'; | ||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : | ||
typeof define === 'function' && define.amd ? define(factory) : | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.memoizeOne = factory()); | ||
}(this, (function () { 'use strict'; | ||
@@ -55,7 +55,4 @@ var safeIsNaN = Number.isNaN || | ||
exports.default = memoizeOne; | ||
exports.memoizeOne = memoizeOne; | ||
return memoizeOne; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
}))); |
@@ -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="undefined"!=typeof globalThis?globalThis:e||self).memoizeOne={})}(this,(function(e){"use strict";var n=Number.isNaN||function(e){return"number"==typeof e&&e!=e};function t(e,t){if(e.length!==t.length)return!1;for(var r=0;r<e.length;r++)if(i=e[r],o=t[r],!(i===o||n(i)&&n(o)))return!1;var i,o;return!0}function r(e,n){var r;void 0===n&&(n=t);var i,o=[],f=!1;return function(){for(var t=[],u=0;u<arguments.length;u++)t[u]=arguments[u];return f&&r===this&&n(t,o)||(i=e.apply(this,t),f=!0,r=this,o=t),i}}e.default=r,e.memoizeOne=r,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).memoizeOne=n()}(this,(function(){"use strict";var e=Number.isNaN||function(e){return"number"==typeof e&&e!=e};function n(n,t){if(n.length!==t.length)return!1;for(var r=0;r<n.length;r++)if(i=n[r],o=t[r],!(i===o||e(i)&&e(o)))return!1;var i,o;return!0}return function(e,t){var r;void 0===t&&(t=n);var i,o=[],f=!1;return function(){for(var n=[],u=0;u<arguments.length;u++)n[u]=arguments[u];return f&&r===this&&t(n,o)||(i=e.apply(this,n),f=!0,r=this,o=n),i}}})); |
{ | ||
"name": "memoize-one", | ||
"version": "5.2.0", | ||
"version": "5.2.1", | ||
"description": "A memoization library which only remembers the latest invocation", | ||
@@ -5,0 +5,0 @@ "main": "dist/memoize-one.cjs.js", |
@@ -16,3 +16,3 @@ # memoize-one | ||
Unlike other memoization libraries, `memoize-one` only remembers the latest arguments and result. No need to worry about cache busting mechanisms such as `maxAge`, `maxSize`, `exclusions` and so on which can be prone to memory leaks. `memoize-one` simply remembers the last arguments, and if the function is next called with the same arguments then it returns the previous result. | ||
Unlike other memoization libraries, `memoize-one` only remembers the latest arguments and result. No need to worry about cache busting mechanisms such as `maxAge`, `maxSize`, `exclusions` and so on, which can be prone to memory leaks. `memoize-one` simply remembers the last arguments, and if the function is next called with the same arguments then it returns the previous result. | ||
@@ -22,3 +22,4 @@ ## Usage | ||
```js | ||
import { memoizeOne } from 'memoize-one'; | ||
// memoize-one uses the default import | ||
import memoizeOne from 'memoize-one'; | ||
@@ -45,11 +46,2 @@ const add = (a, b) => a + b; | ||
You can use the default export or a named import | ||
```js | ||
// Named import | ||
import { memoizeOne } from 'memoize-one'; | ||
// Default import | ||
import memoizeOne from 'memoize-one'; | ||
``` | ||
## Installation | ||
@@ -73,3 +65,3 @@ | ||
2. each new argument has strict equality (`===`) with the previous argument | ||
3. **[special case]** if the arguments are not `===` and they are both `NaN` then the argument is treated as equal | ||
3. **[special case]** if two arguments are not `===` and they are both `NaN` then the two arguments are treated as equal | ||
@@ -79,3 +71,3 @@ What this looks like in practice: | ||
```js | ||
import { memoizeOne } from 'memoize-one'; | ||
import memoizeOne from 'memoize-one'; | ||
@@ -106,3 +98,4 @@ // add all numbers provided to the function | ||
memoizedAdd(1, 3); | ||
// the first value is not `===` to the previous first value (1 !== 3), so add function is called again | ||
// the first value is not `===` to the previous first value (1 !== 3) | ||
// so add function is called again | ||
memoizedAdd(3, 1); | ||
@@ -163,3 +156,3 @@ ``` | ||
result1 === result2; // false - difference reference | ||
result1 === result2; // false - different object reference | ||
@@ -166,0 +159,0 @@ const result3 = deepMemoized({ foo: 'bar' }); |
@@ -37,3 +37,5 @@ import areInputsEqual from './are-inputs-equal'; | ||
export default memoizeOne; | ||
// named export | ||
export { memoizeOne }; | ||
// disabled for now as mixing named and | ||
// default exports is problematic with CommonJS | ||
// export { memoizeOne }; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
0
21770
222
269