source: frontend/node_modules/enhanced-resolve/lib/util/memoize.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 711 bytes
Line 
1/*
2 MIT License http://www.opensource.org/licenses/mit-license.php
3 Author Tobias Koppers @sokra
4*/
5
6"use strict";
7
8/**
9 * @template T
10 * @typedef {() => T} FunctionReturning
11 */
12
13/**
14 * @template T
15 * @param {FunctionReturning<T>} fn memorized function
16 * @returns {FunctionReturning<T>} new function
17 */
18const memoize = (fn) => {
19 let cache = false;
20 /** @type {T | undefined} */
21 let result;
22 return () => {
23 if (cache) {
24 return /** @type {T} */ (result);
25 }
26
27 result = fn();
28 cache = true;
29 // Allow to clean up memory for fn
30 // and all dependent resources
31 /** @type {FunctionReturning<T> | undefined} */
32 (fn) = undefined;
33 return /** @type {T} */ (result);
34 };
35};
36
37module.exports = memoize;
Note: See TracBrowser for help on using the repository browser.