src/utils/bindProps.js
/**
 * Binds the properties defined in props to the google maps instance.
 * If the prop is an Object type, and we wish to track the properties
 * of the object (e.g. the lat and lng of a LatLng), then we do a deep
 * watch. For deep watch, we also prevent the _changed event from being
 * $emitted if the data source was external.
 */
Binds the properties defined in props to the google maps instance.
If the prop is an Object type, and we wish to track the properties
of the object , then we do a deep
watch. For deep watch, we also prevent the _changed event from being
$emitted if the data source was external.
Binds the properties defined in props to the google maps instance . If the prop is an Object type and we wish to track the properties of the object then we do a deep watch . For deep watch we also prevent the _changed event from being $emitted if the data source was external .
function bindProps(vueInst, googleMapsInst, props) {
  for (let attribute in props) {
    let { twoWay, type, trackProperties, noBind } = props[attribute]
    if (noBind) continue
    const setMethodName = 'set' + Str.capitalizeFirstLetter(attribute)
    const getMethodName = 'get' + Str.capitalizeFirstLetter(attribute)
    const eventName = attribute.toLowerCase() + '_changed'
    const initialValue = vueInst[attribute]
    if (typeof googleMapsInst[setMethodName] === 'undefined') {
      throw new Error(
        `${setMethodName} is not a method of (the Maps object corresponding to) ${vueInst.$options._componentTag}`
      )
    }
    if (type !== Object || !trackProperties) {
      vueInst.$watch(attribute,
        () => {
          const attributeValue = vueInst[attribute]
          googleMapsInst[setMethodName](attributeValue)
        },
        {
          immediate: typeof initialValue !== 'undefined',
          deep: type === Object,
        }
      )
    } else {
      WatchPrimitiveProperties(
        vueInst,
        trackProperties.map((prop) => `${attribute}.${prop}`),
        () => {
          googleMapsInst[setMethodName](vueInst[attribute])
        },
        vueInst[attribute] !== undefined
      )
    }
    if (twoWay && (vueInst.$gmapOptions.autobindAllEvents || vueInst.$attrs[eventName])) {
      googleMapsInst.addListener(eventName, () => {
        vueInst.$emit(eventName, googleMapsInst[getMethodName]())
      })
    }
  }
}
function bindProps ( vueInst , googleMapsInst , props ) { for ( let attribute in props ) { let { twoWay , type , trackProperties , noBind } = props [ attribute ] if ( noBind ) continue const setMethodName = 'set' + Str . capitalizeFirstLetter ( attribute ) const getMethodName = 'get' + Str . capitalizeFirstLetter ( attribute ) const eventName = attribute . toLowerCase ( ) + '_changed' const initialValue = vueInst [ attribute ] if ( typeof googleMapsInst [ setMethodName ] === 'undefined' ) { throw new Error ( ` ${ setMethodName } ${ vueInst . $options . _componentTag } ` ) } if ( type !== Object || ! trackProperties ) { vueInst . $watch ( attribute , ( ) => { const attributeValue = vueInst [ attribute ] googleMapsInst [ setMethodName ] ( attributeValue ) } , { immediate : typeof initialValue !== 'undefined' , deep : type === Object , } ) } else { WatchPrimitiveProperties ( vueInst , trackProperties . map ( ( prop ) => ` ${ attribute } ${ prop } ` ) , ( ) => { googleMapsInst [ setMethodName ] ( vueInst [ attribute ] ) } , vueInst [ attribute ] !== undefined ) } if ( twoWay && ( vueInst . $gmapOptions . autobindAllEvents || vueInst . $attrs [ eventName ] ) ) { googleMapsInst . addListener ( eventName , ( ) => { vueInst . $emit ( eventName , googleMapsInst [ getMethodName ] ( ) ) } ) } } }
Binds the properties defined in props to the google maps instance.
Binds the properties defined in props to the google maps instance .
// We need to avoid an endless // propChanged -> event $emitted -> propChanged -> event $emitted loop // although this may really be the user's responsibility // Track the object deeply // eslint-disable-line no-unused-vars