@netlify/build
Version:
Netlify build module
16 lines (15 loc) • 535 B
JavaScript
import memoizeOne from 'memoize-one';
// Add a `object[propName]` whose value is the return value of `getFunc()`, but
// is only retrieved when accessed.
export const addLazyProp = function (object, propName, getFunc) {
const mGetFunc = memoizeOne(getFunc, returnTrue);
// Mutation is required due to the usage of `Object.defineProperty()`
Object.defineProperty(object, propName, {
get: mGetFunc,
enumerable: true,
configurable: true,
});
};
const returnTrue = function () {
return true;
};