mrichar1 / jsonapi-vuex

Use a JSONAPI api with a Vuex store, with data restructuring/normalization.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Getters are undefined

geoidesic opened this issue · comments

So if my namespaces store doesn't use jvModule, like so:

export const namespaced = true;
export const state = stateImport;
export const getters = getterImport;
export const mutations = mutationImport;
export const actions = actionImport;

Then I can access the getter just find in component created hook:

console.log(
        this.$store.getters["queue/messages"]. // outputs `[]` which is the expected value
      );

However if I instead make use of a jvModule store like so:

export const mutations = _.merge(jvModule["mutations"], mutationImport);
export const getters = _.merge(jvModule["getters"], getterImport);
export const actions = _.merge(jvModule["actions"], actionImport);
export const state = _.merge(jvModule["state"], stateImport);
export const namespaced = true;

Then the output is undefined. Even more weird is that if I console.log the getter collection, it shows as defined.

 console.log src/components/shared/tool-bar.vue:56
    this.$store.getters {
      'queue/messages': [Getter]
    }

  console.log src/components/shared/tool-bar.vue:57
    this.$store.getters['queue/messages'] undefined

I don't know what to make of that.

Must be something I'm doing wrong because a basic example I built on codesandbox works.

Oh.. no, I was wrong it doesn't work in codesandbox either. Here's the sandbox:
https://codesandbox.io/s/jsonapi-vuex-jest-zrijt

Have a look at the HelloWorld component's computed property and look at the console log. Getters don't seem to work at all. Or am I doing it wrong?

I've also tried to set up a basic example based on the code in your repo in the examples folder... but I couldn't get that to work either: https://codesandbox.io/s/jsonapi-vuex-jest-q6y84

Closing as this is solved by #135