mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-10-11 14:14:36 +08:00
DISABLE_THIRD_PARTY_CHECK=new npm module causes package-lock change We can get rid of a custom script and use ESLint for these rules. Additionally this means editors will highlight the issue in the editor. Change-Id: I552b52e7f07b4e7430b3f685dbc3b5fad36ffff2 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2052167 Reviewed-by: Paul Lewis <aerotwist@chromium.org> Commit-Queue: Jack Franklin <jacktfranklin@chromium.org>
43 lines
1.3 KiB
JavaScript
43 lines
1.3 KiB
JavaScript
import _arity from './internal/_arity.js';
|
|
import _curry2 from './internal/_curry2.js';
|
|
import _has from './internal/_has.js';
|
|
|
|
/**
|
|
* Creates a new function that, when invoked, caches the result of calling `fn`
|
|
* for a given argument set and returns the result. Subsequent calls to the
|
|
* memoized `fn` with the same argument set will not result in an additional
|
|
* call to `fn`; instead, the cached result for that set of arguments will be
|
|
* returned.
|
|
*
|
|
*
|
|
* @func
|
|
* @memberOf R
|
|
* @since v0.24.0
|
|
* @category Function
|
|
* @sig (*... -> String) -> (*... -> a) -> (*... -> a)
|
|
* @param {Function} fn The function to generate the cache key.
|
|
* @param {Function} fn The function to memoize.
|
|
* @return {Function} Memoized version of `fn`.
|
|
* @example
|
|
*
|
|
* let count = 0;
|
|
* const factorial = R.memoizeWith(R.identity, n => {
|
|
* count += 1;
|
|
* return R.product(R.range(1, n + 1));
|
|
* });
|
|
* factorial(5); //=> 120
|
|
* factorial(5); //=> 120
|
|
* factorial(5); //=> 120
|
|
* count; //=> 1
|
|
*/
|
|
var memoizeWith = /*#__PURE__*/_curry2(function memoizeWith(mFn, fn) {
|
|
var cache = {};
|
|
return _arity(fn.length, function () {
|
|
var key = mFn.apply(this, arguments);
|
|
if (!_has(key, cache)) {
|
|
cache[key] = fn.apply(this, arguments);
|
|
}
|
|
return cache[key];
|
|
});
|
|
});
|
|
export default memoizeWith; |