I have two modules, let's call them core and implementation. How can I set up the store to enable things in core to rely on an assumed store provided by the implementation?
In the implementation's store I am doing something like this:
import Core from 'core'
export default new Vuex.Store(
new Core().defaultStore
)
That will register default state, mutations, actions and getters (the setup allows the user of implementation to extend/modify a default store provided by core).
The problem arises in an action inside core when it tries to access a getter in a non vue JS file.
export default class SomeClassInCore {
exampleMethod() {
// The getters will not be accessible here!
return store.getters.someKey
}
}
Is there some way to achieve "runtime" resolving of the "master" store? I was thinking about if I somehow can use window to access the Vue instance created by the implementation repo?
I tried doing it like this
import store from './store.js'
import Vue from 'vue'
import { CoreVueTools } from 'core'
window.Vue = Vue
window.store = store
Vue.use(CoreVueTools)
new Vue({
el: '#app',
store
})
And then accessing it like this
exampleMethod() {
return window.store.getters.someKey
}
That works, but I'm not super happy about this solution, there has to be a better way than relying on window right? Can I use another design pattern?