UNPKG

1.03 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = memoize3;
7
8/**
9 * Copyright (c) 2017-present, Facebook, Inc.
10 *
11 * This source code is licensed under the MIT license found in the
12 * LICENSE file in the root directory of this source tree.
13 *
14 * strict
15 */
16
17/**
18 * Memoizes the provided three-argument function.
19 */
20function memoize3(fn) {
21 var cache0;
22
23 function memoized(a1, a2, a3) {
24 if (!cache0) {
25 cache0 = new WeakMap();
26 }
27
28 var cache1 = cache0.get(a1);
29 var cache2;
30
31 if (cache1) {
32 cache2 = cache1.get(a2);
33
34 if (cache2) {
35 var cachedValue = cache2.get(a3);
36
37 if (cachedValue !== undefined) {
38 return cachedValue;
39 }
40 }
41 } else {
42 cache1 = new WeakMap();
43 cache0.set(a1, cache1);
44 }
45
46 if (!cache2) {
47 cache2 = new WeakMap();
48 cache1.set(a2, cache2);
49 }
50
51 var newValue = fn.apply(this, arguments);
52 cache2.set(a3, newValue);
53 return newValue;
54 }
55
56 return memoized;
57}
\No newline at end of file