molstar
Version:
A comprehensive macromolecular library.
45 lines • 1.45 kB
JavaScript
/**
* Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
*
* @author David Sehnal <david.sehnal@gmail.com>
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.memoize1 = exports.memoizeLatest = void 0;
/** Cache the latest result from calls to a function with any number of arguments */
function memoizeLatest(f) {
var lastArgs = void 0, value = void 0;
return function () {
var args = [];
for (var _a = 0; _a < arguments.length; _a++) {
args[_a] = arguments[_a];
}
if (!lastArgs || lastArgs.length !== args.length) {
lastArgs = args;
value = f.apply(void 0, args);
return value;
}
for (var i = 0, _i = args.length; i < _i; i++) {
if (args[i] !== lastArgs[i]) {
lastArgs = args;
value = f.apply(void 0, args);
return value;
}
}
return value;
};
}
exports.memoizeLatest = memoizeLatest;
/** Cache all results from calls to a function with a single argument */
function memoize1(f) {
var cache = new Map();
return function (a) {
if (cache.has(a))
return cache.get(a);
var v = f(a);
cache.set(a, v);
return v;
};
}
exports.memoize1 = memoize1;
//# sourceMappingURL=memoize.js.map
;