import { Stylesheet } from '@uifabric/merge-styles' ; const stylesheet = Stylesheet . getInstance ( ) ; if ( stylesheet && stylesheet . onReset ) { Stylesheet . getInstance ( ) . onReset ( resetMemoizations ) ; } declare class WeakMap { public get ( key ) ; public set ( key , value ) ; public has ( key ) ; } let _resetCounter = 0 ; const _emptyObject = { empty : true } ; const _dictionary = { } ; let _weakMap = typeof WeakMap === 'undefined' ? null : WeakMap ; interface IMemoizeNode { map : WeakMap | null ; value ? : any ; } internal export function setMemoizeWeakMap ( weakMap ) { _weakMap = weakMap ; } /**
 * Reset memoizations.
 */ export function resetMemoizations ( ) { _resetCounter ++ ; } public export function memoize < T extends Function > ( target , key , descriptor ) { let fn = memoizeFunction ( descriptor . value && descriptor . value . bind ( null ) ) ; return { configurable : true , get ( ) { return fn ; } } ; } public param cb param maxCacheSize returns export function memoizeFunction < T extends ( ... args : any [ ] ) => RET_TYPE , RET_TYPE > ( cb , maxCacheSize = 100 ) { if ( ! _weakMap ) { return cb ; } let rootNode ; let cacheSize = 0 ; let localResetCounter = _resetCounter ; return function memoizedFunction ( ... args ) : RET_TYPE { let currentNode = rootNode ; if ( rootNode === undefined || localResetCounter !== _resetCounter || ( maxCacheSize > 0 && cacheSize > maxCacheSize ) ) { rootNode = _createNode ( ) ; cacheSize = 0 ; localResetCounter = _resetCounter ; } currentNode = rootNode ; for ( let i = 0 ; i < args . length ; i ++ ) { let arg = _normalizeArg ( args [ i ] ) ; if ( ! currentNode . map . has ( arg ) ) { currentNode . map . set ( arg , _createNode ( ) ) ; } currentNode = currentNode . map . get ( arg ) ; } if ( ! currentNode . hasOwnProperty ( 'value' ) ) { currentNode . value = cb ( ... args ) ; cacheSize ++ ; } return currentNode . value ; } as any ; } function _normalizeArg ( val ) ; function _normalizeArg ( val ) ; function _normalizeArg ( val ) { if ( ! val ) { return _emptyObject ; } else if ( typeof val === 'object' || typeof val === 'function' ) { return val ; } else if ( ! _dictionary [ val ] ) { _dictionary [ val ] = { val } ; } return _dictionary [ val ] ; } function _createNode ( ) { return { map : _weakMap ? new _weakMap ( ) : null } ; }