Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught TypeError: rootCommit is undefined #55

Open
rostamiani opened this issue Jul 14, 2020 · 1 comment
Open

Uncaught TypeError: rootCommit is undefined #55

rostamiani opened this issue Jul 14, 2020 · 1 comment

Comments

@rostamiani
Copy link

I have several modules and want to commit chat module from one on actions of the user module.

The problem:

i cannot use rootCommit. There is no Type error but at runtime this error occures:

Uncaught TypeError: rootCommit is undefined

This is my store:

const {
  store,
  rootActionContext,
  moduleActionContext,
  rootGetterContext,
  moduleGetterContext,
} = createDirectStore({
  state: {
    initialised: false,
  },
  actions: {
    // Some actions
  },
  mutations: {
    setInit(states) {
      states.initialised = true;
    },
  },
  modules: {
    chat: chatModule,
    user: userModule,
    session: sessionModule,
  },
});

export {
  store,
  rootActionContext,
  moduleActionContext,
  rootGetterContext,
  moduleGetterContext,
};

My userModule:

export const userModule = defineModule({
  namespaced: true as true,
  state: {
    userList: [],
    currentUserId: 0,
  } as UserStates,

  actions: userActions,
  mutations: userMutations,
  getters: userGetters,
});

And this is a part of my userActions:

export const userActions = defineActions({

  join(context) {
    const { rootCommit } = storeActionContext(context);
    
    Server.instance.send('something').subscribe((message)=>{
      rootCommit.chat.addMessage(message);
    })

  }

}

const storeActionContext = (context: any) =>
  moduleActionContext(context, userModule);
@paleo
Copy link
Collaborator

paleo commented Jul 16, 2020

It should work. Maybe you could add some debug log:

  join(context) {
    const directContext = storeActionContext(context);    
    Server.instance.send('something').subscribe((message)=>{
      console.log("directContext", directContext);
      directContext.rootCommit.chat.addMessage(message);
    })
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants