Vuex 3 vs Vuex 4 getters: change in behaviour if applied to nested objects?

139 Views Asked by At

I used to be able to apply a reactive getter to a nested method inside an object instance stored in my vuex state, but this doesn't appear to work anymore.

In this particular case, it was a mapbox instance which was created and then stored inside the vuex v3 store's state. I could then share this instance amongst various components and could also watch the instance for changes via reactive getters.

For example:

state: {
  mapInstance: null, // <- gets assigned with a mapbox instance
  // mapInstance contains a method called "getZoom()"
},
getters: {
  zoom: (state) => (state.mapInstance ? state.mapInstance.getZoom() : null),
}

However, the reactive getters no longer work for this use case in vuex v4.

I'm assuming something has changed in the internals of vuex v3 vs. v4: is there a way to deliberately expose certain nested properties or methods to reactive getters in vuex v4?

0

There are 0 best solutions below