Skip to content

The third parameter of dispatch is undefined. #1618

Closed
@yywc

Description

@yywc

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions