UNPKG

@adobe/uxp-optimized

Version:

Library of react components optimized for Adobe's Unified Extensibility Platform

32 lines (30 loc) 927 B
"use strict"; /* Copyright 2019 Adobe All Rights Reserved. NOTICE: Adobe permits you to use, modify, and distribute this file in accordance with the terms of the Adobe license agreement accompanying it. If you have received this file from a source other than Adobe, then your use, modification, or distribution of it requires the prior written permission of Adobe. */ Object.defineProperty(exports, "__esModule", { value: true }); function memoize(fn) { const symbol = Symbol(); const cache = new WeakMap(); return (input) => { const e = Object.isExtensible(input); let value = e ? input[symbol] : cache.get(input); if (value === undefined) { value = fn(input); if (e) { input[symbol] = value; } else { cache.set(input, value); } } return value; }; } exports.default = memoize;