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

The third parameter of dispatch is undefined. #1618

Closed
yywc opened this issue Sep 20, 2019 · 1 comment · Fixed by #1640

Comments

@yywc
Copy link

@yywc yywc commented Sep 20, 2019

Version

3.1.1

Reproduction link

https://codesandbox.io/s/vue-template-4fv3d

Steps to reproduce

  1. go to link;
  2. open Console of page in the bottom;
  3. see the undefined;

What is expected?

In theory,it should show the code of cb.

What is actually happening?

In fact,it's undefined.


According to Vuex code, wrappedActionHandler function provide two params.One is payload,the other is cb.

  // notice the cb
  entry.push(function wrappedActionHandler (payload, cb) {
    let res = handler.call(store, {
      dispatch: local.dispatch,
      commit: local.commit,
      getters: local.getters,
      state: local.state,
      rootGetters: store.getters,
      rootState: store.state
    }, payload, cb) // pass it and do nothing
    if (!isPromise(res)) {
      res = Promise.resolve(res)
    }
    if (store._devtoolHook) {
      return res.catch(err => {
        store._devtoolHook.emit('vuex:error', err)
        throw err
      })
    } else {
      return res
    }
  })

  // dispatch function only use payload
  dispatch (_type, _payload) {
    // check object-style dispatch
    const {
      type,
      payload
    } = unifyObjectStyle(_type, _payload)

    const action = { type, payload }
    const entry = this._actions[type]
    // ...
    const result = entry.length > 1
      ? Promise.all(entry.map(handler => handler(payload))) // only payload parameter
      : entry[0](payload)
  }

So I think cb parameter is useless and it should be delete from code in order to
eliminate misunderstanding.

@gitlab-winnie

This comment has been minimized.

Copy link
Contributor

@gitlab-winnie gitlab-winnie commented Oct 30, 2019

This may be a duplicate of #1571.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.