license let globalNameSpace ; export function getGlobalNamespace ( ) { if ( globalNameSpace == null ) { let ns ; if ( typeof ( window ) !== 'undefined' ) { ns = window ; } else if ( typeof ( global ) !== 'undefined' ) { ns = global ; } else if ( typeof ( process ) !== 'undefined' ) { ns = process ; } else if ( typeof ( self ) !== 'undefined' ) { ns = self ; } else { throw new Error ( 'Could not find a global object' ) ; } globalNameSpace = ns ; } return globalNameSpace ; } function getGlobalMap ( ) { const ns = getGlobalNamespace ( ) ; if ( ns . _tfGlobals == null ) { ns . _tfGlobals = new Map ( ) ; } return ns . _tfGlobals ; } param key param init export function getGlobal < T > ( key , init ) { const globalMap = getGlobalMap ( ) ; if ( globalMap . has ( key ) ) { return globalMap . get ( key ) ; } else { const singleton = init ( ) ; globalMap . set ( key , singleton ) ; return globalMap . get ( key ) ; } }