mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-04 08:57:49 +00:00
Remove semicolons.
This commit is contained in:
46
memoize.js
46
memoize.js
@@ -1,4 +1,4 @@
|
||||
import MapCache from './.internal/MapCache.js';
|
||||
import MapCache from './.internal/MapCache.js'
|
||||
|
||||
/**
|
||||
* Creates a function that memoizes the result of `func`. If `resolver` is
|
||||
@@ -20,47 +20,47 @@ import MapCache from './.internal/MapCache.js';
|
||||
* @returns {Function} Returns the new memoized function.
|
||||
* @example
|
||||
*
|
||||
* const object = { 'a': 1, 'b': 2 };
|
||||
* const other = { 'c': 3, 'd': 4 };
|
||||
* const object = { 'a': 1, 'b': 2 }
|
||||
* const other = { 'c': 3, 'd': 4 }
|
||||
*
|
||||
* const values = memoize(values);
|
||||
* values(object);
|
||||
* const values = memoize(values)
|
||||
* values(object)
|
||||
* // => [1, 2]
|
||||
*
|
||||
* values(other);
|
||||
* values(other)
|
||||
* // => [3, 4]
|
||||
*
|
||||
* object.a = 2;
|
||||
* values(object);
|
||||
* object.a = 2
|
||||
* values(object)
|
||||
* // => [1, 2]
|
||||
*
|
||||
* // Modify the result cache.
|
||||
* values.cache.set(object, ['a', 'b']);
|
||||
* values(object);
|
||||
* values.cache.set(object, ['a', 'b'])
|
||||
* values(object)
|
||||
* // => ['a', 'b']
|
||||
*
|
||||
* // Replace `memoize.Cache`.
|
||||
* memoize.Cache = WeakMap;
|
||||
* memoize.Cache = WeakMap
|
||||
*/
|
||||
function memoize(func, resolver) {
|
||||
if (typeof func != 'function' || (resolver != null && typeof resolver != 'function')) {
|
||||
throw new TypeError('Expected a function');
|
||||
throw new TypeError('Expected a function')
|
||||
}
|
||||
const memoized = function(...args) {
|
||||
const key = resolver ? resolver.apply(this, args) : args[0];
|
||||
const cache = memoized.cache;
|
||||
const key = resolver ? resolver.apply(this, args) : args[0]
|
||||
const cache = memoized.cache
|
||||
|
||||
if (cache.has(key)) {
|
||||
return cache.get(key);
|
||||
return cache.get(key)
|
||||
}
|
||||
const result = func.apply(this, args);
|
||||
memoized.cache = cache.set(key, result) || cache;
|
||||
return result;
|
||||
};
|
||||
memoized.cache = new (memoize.Cache || MapCache);
|
||||
return memoized;
|
||||
const result = func.apply(this, args)
|
||||
memoized.cache = cache.set(key, result) || cache
|
||||
return result
|
||||
}
|
||||
memoized.cache = new (memoize.Cache || MapCache)
|
||||
return memoized
|
||||
}
|
||||
|
||||
memoize.Cache = MapCache;
|
||||
memoize.Cache = MapCache
|
||||
|
||||
export default memoize;
|
||||
export default memoize
|
||||
|
||||
Reference in New Issue
Block a user