Use the isServer utility function instead of multiple duplicate codes

This commit is contained in:
Fawad Mirzad
2021-02-13 19:30:30 +01:00
parent c2beadf477
commit 23000eabc8

View File

@@ -14,6 +14,7 @@ import Autocomplete from './components/autocomplete.vue'
import MapElementMixin from './components/mapElementMixin' import MapElementMixin from './components/mapElementMixin'
import MapElementFactory from './components/mapElementFactory' import MapElementFactory from './components/mapElementFactory'
import MountableMixin from './utils/mountableMixin' import MountableMixin from './utils/mountableMixin'
import {Env} from "./utils/env";
let GmapApi = null let GmapApi = null
export { export {
@@ -86,14 +87,13 @@ function makeGmapApiPromiseLazy(options) {
return lazy(() => { return lazy(() => {
// Load the // Load the
// This will only be evaluated once // This will only be evaluated once
if (typeof window === 'undefined') { if (Env.isServer()) {
// server side -- never resolve this promise
return new Promise(() => {}).then(onApiLoaded) return new Promise(() => {}).then(onApiLoaded)
} else { } else {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
try { try {
window['vueGoogleMapsInit'] = resolve window['vueGoogleMapsInit'] = resolve
loadGMapApi(options.load, options.loadCn) loadGMapApi(options.load)
} catch (err) { } catch (err) {
reject(err) reject(err)
} }
@@ -105,8 +105,7 @@ function makeGmapApiPromiseLazy(options) {
// end-users with the global `vueGoogleMapsInit: () => undefined` // end-users with the global `vueGoogleMapsInit: () => undefined`
// when the Google Maps API has been loaded // when the Google Maps API has been loaded
const promise = new Promise((resolve) => { const promise = new Promise((resolve) => {
if (typeof window === 'undefined') { if (Env.isServer()) {
// Do nothing if run from server-side
return return
} }
window['vueGoogleMapsInit'] = resolve window['vueGoogleMapsInit'] = resolve