The right way coding in Vue 3 compositive API

879
4
06-26-2022 11:40 PM
baohuachu7
New Contributor II

To share the Map or MapView object through the application, what's the right way in Vue 3 dev environment?

To use "Provide/Inject" or "Vuex" state management ?   In this thread  it seems the Js SDK not support proxy so the Map objects are not reactive.   What about the current version of SDK? 

Tags (1)
0 Kudos
4 Replies
ReneRubalcava
Frequent Contributor

I don't want to dictate it as the right way, but this is an example of how I manage ArcGIS JSAPI in Vue.

https://github.com/odoe/nearby-app/blob/main/src/store.ts

You can also use shallowRef in components for stuff if you like. This will just wrap the instance in a Proxy and not all of it's props

https://vuejs.org/api/reactivity-advanced.html#shallowref

I very much recommend that ArcGIS JSAPI not be referenced directly in components, but again, that is just my opinion.

0 Kudos
baohuachu7
New Contributor II

Hi Rene:

   What do you mean : ArcGIS JSAPI not be referenced directly in components  ?

   If not use the reactive features for  ArcGIS JSAPI , only those on Vue side use reactive, and use Accessor watch method, or watchUtils     to handle Map or MapView changes.  Is this way OK?  (as discussed in this thread)  . 

0 Kudos
ReneRubalcava
Frequent Contributor

I prefer to isolate references to the JSAPI in the store or utility modules, but components not to import things like the Map or MapView directly.

0 Kudos
baohuachu2
New Contributor II

Hi  Rene,

Thank you for your help.  

0 Kudos