如何在Redux商店中存储Google地图?

时间:2017-02-27 01:18:57

标签: javascript google-maps reactjs google-chrome-extension redux

我有一个Chrome扩展程序,我使用redux操作在content脚本和background脚本之间传递消息。

由于我无法在script脚本中加载Google地图content标记,因此我尝试将其加载到background脚本&

时将其传递给content脚本。

background脚本中,我运行以下命令:

  // this asynchronously inserts a script tag & calls a callback upon completion
  import load from 'little-loader' 

  window._dispatchMap_ = () => {
     store.dispatch({type: 'MAPS_LOADED', payload: google.maps})
  }

 load('https://maps.google.com/maps/api/js?key=<redacted>&libraries=places&callback=_dispatchMap_', (err) => {
      if (err) console.error(err)
    })

redux操作正确调度,在我的background.html中,redux logger显示正确的有效负载。当我在控制台中检查google.maps obj的大小时:

> Object.keys(google.maps).length // 66 keys

但是,当payload存储在我的redux商店(background仍然存在)中时,它只会保存30个密钥。因此,当它到达我的content脚本(到React组件google-map-react)时,无法正确加载。

为什么google.maps对象无法将redux存储完全保存?

0 个答案:

没有答案