@navinc/base-react-components
Version:
Nav's Pattern Library
18 lines • 1.52 kB
JavaScript
import { global, loadScript } from '@navinc/utils';
const anyGlobal = global;
const typedGlobal = global;
typedGlobal._loadPlacesAutocompletePromise = null;
export const loadPlacesAutocomplete = () => {
var _a, _b, _c, _d;
if (!typedGlobal._loadPlacesAutocompletePromise) {
typedGlobal._loadPlacesAutocompletePromise = Promise.resolve(
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- google isn't available on load
(_d = (_c = (_b = (_a = anyGlobal === null || anyGlobal === void 0 ? void 0 : anyGlobal.google) === null || _a === void 0 ? void 0 : _a.maps) === null || _b === void 0 ? void 0 : _b.places) === null || _c === void 0 ? void 0 : _c.Autocomplete) !== null && _d !== void 0 ? _d : loadScript('https://maps.googleapis.com/maps/api/js?key=AIzaSyAvfE0mS4qeMdHm2fsIfE2XowJj6XG2pW8&libraries=places').then(() => {
var _a, _b, _c, _d;
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- google isn't available on load
return (_d = (_c = (_b = (_a = anyGlobal === null || anyGlobal === void 0 ? void 0 : anyGlobal.google) === null || _a === void 0 ? void 0 : _a.maps) === null || _b === void 0 ? void 0 : _b.places) === null || _c === void 0 ? void 0 : _c.Autocomplete) !== null && _d !== void 0 ? _d : Promise.reject(new Error('Error loading GoogleMaps script'));
}));
}
return typedGlobal._loadPlacesAutocompletePromise;
};
//# sourceMappingURL=load-places-autocomplete.js.map