refactor(memoizeN): extract support code out of closure (#7805)

This commit is contained in:
Vladimir Gorej
2022-01-27 08:57:50 +01:00
committed by GitHub
parent d638e58527
commit 3ce6477007

View File

@@ -7,13 +7,14 @@ import memoize from "lodash/memoize"
* storing the result based on the arguments provided to the memoized function.
*/
const memoizeN = (fn, resolver = ((...args) => args)) => {
const shallowArrayEquals = (a) => (b) => {
return Array.isArray(a) && Array.isArray(b)
&& a.length === b.length
&& a.every((val, index) => val === b[index])
}
const list = (...args) => args
class Cache extends Map {
delete(key) {
const keys = Array.from(this.keys())
@@ -33,6 +34,7 @@ const memoizeN = (fn, resolver = ((...args) => args)) => {
}
}
const memoizeN = (fn, resolver = list) => {
const { Cache: OriginalCache } = memoize
memoize.Cache = Cache