const emojiCache = new Map < string , Promise < string > > ( ) ; const getEmoji = ( userId ) : Promise < string > => { const getTokenRequestOptions = { headers : { 'Content-Type' : 'application/json' } , method : 'GET' } ; return new Promise < string > ( ( resolve ) => { fetch ( '/userConfig/' + userId , getTokenRequestOptions ) . then ( ( data ) => { return data . json ( ) ; } ) . then ( ( json ) => { resolve ( json . emoji ) ; } ) . catch ( ( error ) => { console . error ( 'Failed at getting emoji, Error: ' , error ) ; resolve ( '' ) ; } ) ; } ) ; } ; param userId export const fetchEmojiForUser = ( userId ) : Promise < string > => { const emoji = emojiCache . get ( userId ) ; if ( emoji === undefined ) { const promise = getEmoji ( userId ) ; emojiCache . set ( userId , promise ) ; return promise ; } else { return emoji ; } } ;