diff options
author | Minteck <contact@minteck.org> | 2022-10-18 08:59:09 +0200 |
---|---|---|
committer | Minteck <contact@minteck.org> | 2022-10-18 08:59:09 +0200 |
commit | 2c4ae43e688a9873e86211ea0e7aeb9ba770dd77 (patch) | |
tree | 17848d95522dab25d3cdeb9c4a6450e2a234861f /alarm/node_modules/graphql/jsutils/memoize3.js.flow | |
parent | 108525534c28013cfe1897c30e4565f9893f3766 (diff) | |
download | pluralconnect-2c4ae43e688a9873e86211ea0e7aeb9ba770dd77.tar.gz pluralconnect-2c4ae43e688a9873e86211ea0e7aeb9ba770dd77.tar.bz2 pluralconnect-2c4ae43e688a9873e86211ea0e7aeb9ba770dd77.zip |
Update
Diffstat (limited to 'alarm/node_modules/graphql/jsutils/memoize3.js.flow')
-rw-r--r-- | alarm/node_modules/graphql/jsutils/memoize3.js.flow | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/alarm/node_modules/graphql/jsutils/memoize3.js.flow b/alarm/node_modules/graphql/jsutils/memoize3.js.flow new file mode 100644 index 0000000..cd4ccd5 --- /dev/null +++ b/alarm/node_modules/graphql/jsutils/memoize3.js.flow @@ -0,0 +1,39 @@ +// @flow strict +/** + * Memoizes the provided three-argument function. + */ +export default function memoize3< + A1: { ... } | $ReadOnlyArray<mixed>, + A2: { ... } | $ReadOnlyArray<mixed>, + A3: { ... } | $ReadOnlyArray<mixed>, + R: mixed, +>(fn: (A1, A2, A3) => R): (A1, A2, A3) => R { + let cache0; + + return function memoized(a1, a2, a3) { + if (!cache0) { + cache0 = new WeakMap(); + } + let cache1 = cache0.get(a1); + let cache2; + if (cache1) { + cache2 = cache1.get(a2); + if (cache2) { + const cachedValue = cache2.get(a3); + if (cachedValue !== undefined) { + return cachedValue; + } + } + } else { + cache1 = new WeakMap(); + cache0.set(a1, cache1); + } + if (!cache2) { + cache2 = new WeakMap(); + cache1.set(a2, cache2); + } + const newValue = fn(a1, a2, a3); + cache2.set(a3, newValue); + return newValue; + }; +} |