Skip to content

Commit d331e56

Browse files
author
profreelancer222
committed
add other auth
Co-authored-by: arthurkoblet210 <[email protected]> Co-authored-by: arthrukffws <arthrukffws.google.com>
1 parent 988d092 commit d331e56

File tree

1 file changed

+30
-30
lines changed

1 file changed

+30
-30
lines changed

src/helpers.js

+30-30
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,35 @@ export const mapState = normalizeNamespace((namespace, states) => {
6363
return res
6464
})
6565

66-
66+
/**
67+
* Reduce the code which written in Vue.js for dispatch the action
68+
* @param {String} [namespace] - Module's namespace
69+
* @param {Object|Array} actions # Object's item can be a function which accept `dispatch` function as the first param, it can accept anthor params. You can dispatch action and do any other things in this function. specially, You need to pass anthor params from the mapped function.
70+
* @return {Object}
71+
*/
72+
export const mapActions = normalizeNamespace((namespace, actions) => {
73+
const res = {}
74+
if (__DEV__ && !isValidMap(actions)) {
75+
console.error('[vuex] mapActions: mapper parameter must be either an Array or an Object')
76+
}
77+
normalizeMap(actions).forEach(({ key, val }) => {
78+
res[key] = function mappedAction (...args) {
79+
// get dispatch function from store
80+
let dispatch = this.$store.dispatch
81+
if (namespace) {
82+
const module = getModuleByNamespace(this.$store, 'mapActions', namespace)
83+
if (!module) {
84+
return
85+
}
86+
dispatch = module.context.dispatch
87+
}
88+
return typeof val === 'function'
89+
? val.apply(this, [dispatch].concat(args))
90+
: dispatch.apply(this.$store, [val].concat(args))
91+
}
92+
})
93+
return res
94+
})
6795

6896
/**
6997
* Reduce the code which written in Vue.js for getting the getters
@@ -95,35 +123,7 @@ export const mapGetters = normalizeNamespace((namespace, getters) => {
95123
return res
96124
})
97125

98-
/**
99-
* Reduce the code which written in Vue.js for dispatch the action
100-
* @param {String} [namespace] - Module's namespace
101-
* @param {Object|Array} actions # Object's item can be a function which accept `dispatch` function as the first param, it can accept anthor params. You can dispatch action and do any other things in this function. specially, You need to pass anthor params from the mapped function.
102-
* @return {Object}
103-
*/
104-
export const mapActions = normalizeNamespace((namespace, actions) => {
105-
const res = {}
106-
if (__DEV__ && !isValidMap(actions)) {
107-
console.error('[vuex] mapActions: mapper parameter must be either an Array or an Object')
108-
}
109-
normalizeMap(actions).forEach(({ key, val }) => {
110-
res[key] = function mappedAction (...args) {
111-
// get dispatch function from store
112-
let dispatch = this.$store.dispatch
113-
if (namespace) {
114-
const module = getModuleByNamespace(this.$store, 'mapActions', namespace)
115-
if (!module) {
116-
return
117-
}
118-
dispatch = module.context.dispatch
119-
}
120-
return typeof val === 'function'
121-
? val.apply(this, [dispatch].concat(args))
122-
: dispatch.apply(this.$store, [val].concat(args))
123-
}
124-
})
125-
return res
126-
})
126+
127127

128128
/**
129129
* Rebinding namespace param for mapXXX function in special scoped, and return them by simple object

0 commit comments

Comments
 (0)