memoize-one
Advanced tools
Comparing version 3.1.0 to 3.1.1
@@ -7,10 +7,2 @@ | ||
var defineProperty = function defineProperty(target, property, value) { | ||
return Object.defineProperty(target, property, { | ||
writable: false, | ||
configurable: true, | ||
value: value | ||
}); | ||
}; | ||
export default function (resultFn) { | ||
@@ -44,8 +36,3 @@ var isEqual = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : simpleIsEqual; | ||
defineProperty(result, 'length', resultFn.length); | ||
var name = 'memoized_' + (resultFn.name || 'fn'); | ||
defineProperty(result, 'name', name); | ||
return result; | ||
} |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -35,7 +35,2 @@ Object.defineProperty(exports, "__esModule", { | ||
defineProperty(result, 'length', resultFn.length); | ||
var name = 'memoized_' + (resultFn.name || 'fn'); | ||
defineProperty(result, 'name', name); | ||
return result; | ||
@@ -46,10 +41,2 @@ }; | ||
return a === b; | ||
}; | ||
var defineProperty = function defineProperty(target, property, value) { | ||
return Object.defineProperty(target, property, { | ||
writable: false, | ||
configurable: true, | ||
value: value | ||
}); | ||
}; |
{ | ||
"name": "memoize-one", | ||
"version": "3.1.0", | ||
"version": "3.1.1", | ||
"description": "A memoization library which only remembers the latest invocation", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -81,33 +81,2 @@ # memoizeOne | ||
### Dynamic properties | ||
The result function will have the same [`.length` property](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/length) as the provided function. | ||
```js | ||
const add = (a, b) => a + b; | ||
const memoizedAdd = memoizeOne(add); | ||
memoizedAdd.length === 2; // true | ||
``` | ||
- For debug purposes we add a [`.name` property](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name) to the result function. If provided function has a name then the name will be `memoized_${yourFunction.name}`. Otherwise it will be `memoized_fn`. This assists in debugging memoized functions. | ||
```js | ||
// function has a name | ||
const add = (a, b) => a + b; | ||
// the original name is 'add' | ||
add.name === 'add'; // true | ||
// our new memoizedAdd function has a prefixed name | ||
const memoizedAdd = memoizeOne(add); | ||
memoizedAdd.name === 'memoized_add'; // true | ||
``` | ||
```js | ||
// function does not have a name | ||
const memoizedInline = memoizeOne((a, b) => a + b); | ||
memoizedInline.name === 'memoized_fn'; | ||
``` | ||
## Installation | ||
@@ -114,0 +83,0 @@ |
@@ -6,9 +6,2 @@ // @flow | ||
const defineProperty = (target: Object, property: string, value: mixed) => | ||
Object.defineProperty(target, property, { | ||
writable: false, | ||
configurable: true, | ||
value: value, | ||
}); | ||
// <ResultFn: (...Array<any>) => mixed> | ||
@@ -44,13 +37,4 @@ // The purpose of this typing is to ensure that the returned memoized | ||
// Adding a length property | ||
// This is useful for some memoization checks that inspect the length of the function arguments | ||
defineProperty(result, 'length', resultFn.length); | ||
// Giving a useful name to the resulting function | ||
// This is helpful for debug purposes | ||
const name: string = `memoized_${resultFn.name || 'fn'}`; | ||
defineProperty(result, 'name', name); | ||
// telling flow to ignore the type of `result` as we know it is `ResultFn` | ||
return (result: any); | ||
} |
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
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
15252
87
169