Caching JavaScript promise results

前端 未结 6 988
独厮守ぢ
独厮守ぢ 2021-01-03 01:55

I would make one call to the server to get a list of items. How do I make sure that only one call is made and the collections is processed only once to create a key value ma

6条回答
  •  半阙折子戏
    2021-01-03 02:22

    You could also solve this by using a decorators, For an instance by using the debounce decorator from utils-decorator lib (npm install utils-decorators):

    import {memoizeAsync} from 'utils-decorators';
    
    class MyAppComponent {
    
      @memoizeAsync(30000)
      getData(input) {
       ...
      }
    }
    

提交回复
热议问题