memoize3.js 813 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = memoize3;
  6. /**
  7. * Memoizes the provided three-argument function.
  8. */
  9. function memoize3(fn) {
  10. var cache0;
  11. return function memoized(a1, a2, a3) {
  12. if (!cache0) {
  13. cache0 = new WeakMap();
  14. }
  15. var cache1 = cache0.get(a1);
  16. var cache2;
  17. if (cache1) {
  18. cache2 = cache1.get(a2);
  19. if (cache2) {
  20. var cachedValue = cache2.get(a3);
  21. if (cachedValue !== undefined) {
  22. return cachedValue;
  23. }
  24. }
  25. } else {
  26. cache1 = new WeakMap();
  27. cache0.set(a1, cache1);
  28. }
  29. if (!cache2) {
  30. cache2 = new WeakMap();
  31. cache1.set(a2, cache2);
  32. }
  33. var newValue = fn(a1, a2, a3);
  34. cache2.set(a3, newValue);
  35. return newValue;
  36. };
  37. }