nakarte

Source code of https://map.sikmir.ru (fork)
git clone git://git.sikmir.ru/nakarte
Log | Files | Refs | LICENSE

index.js (697B)


      1 import loadScript from 'load-script';
      2 import config from '~/config';
      3 
      4 let _google = null;
      5 let _pending = null;
      6 
      7 function getGoogle() {
      8     if (_google) {
      9         return Promise.resolve(_google);
     10     }
     11     if (!_pending) {
     12         _pending = new Promise((resolve, reject) => {
     13                 loadScript(config.googleApiUrl, (error) => {
     14                         if (error) {
     15                             reject(error);
     16                         } else {
     17                             _google = window.google;
     18                             resolve(_google);
     19                         }
     20                     }
     21                 );
     22             }
     23         );
     24     }
     25     return _pending;
     26 }
     27 
     28 export default getGoogle;