From 82b69b5dc0ced861d2302d8aed1ffb3cf6bfac85 Mon Sep 17 00:00:00 2001 From: UltraDEV007 Date: Sun, 25 Feb 2024 13:02:56 -0500 Subject: [PATCH 1/2] test --- src/helpers.js | 60 ++++++++++++++++++++++++++------------------------ 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/src/helpers.js b/src/helpers.js index 0b2aac7..388bb79 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -1,5 +1,35 @@ import { isObject } from './util' +/** + * Reduce the code which written in Vue.js for committing the mutation + * @param {String} [namespace] - Module's namespace + * @param {Object|Array} mutations # Object's item can be a function which accept `commit` function as the first param, it can accept another params. You can commit mutation and do any other things in this function. specially, You need to pass anthor params from the mapped function. + * @return {Object} + */ +export const mapMutations = normalizeNamespace((namespace, mutations) => { + const res = {} + if (__DEV__ && !isValidMap(mutations)) { + console.error('[vuex] mapMutations: mapper parameter must be either an Array or an Object') + } + normalizeMap(mutations).forEach(({ key, val }) => { + res[key] = function mappedMutation (...args) { + // Get the commit method from store + let commit = this.$store.commit + if (namespace) { + const module = getModuleByNamespace(this.$store, 'mapMutations', namespace) + if (!module) { + return + } + commit = module.context.commit + } + return typeof val === 'function' + ? val.apply(this, [commit].concat(args)) + : commit.apply(this.$store, [val].concat(args)) + } + }) + return res +}) + /** * Reduce the code which written in Vue.js for getting the state. * @param {String} [namespace] - Module's namespace @@ -33,35 +63,7 @@ export const mapState = normalizeNamespace((namespace, states) => { return res }) -/** - * Reduce the code which written in Vue.js for committing the mutation - * @param {String} [namespace] - Module's namespace - * @param {Object|Array} mutations # Object's item can be a function which accept `commit` function as the first param, it can accept another params. You can commit mutation and do any other things in this function. specially, You need to pass anthor params from the mapped function. - * @return {Object} - */ -export const mapMutations = normalizeNamespace((namespace, mutations) => { - const res = {} - if (__DEV__ && !isValidMap(mutations)) { - console.error('[vuex] mapMutations: mapper parameter must be either an Array or an Object') - } - normalizeMap(mutations).forEach(({ key, val }) => { - res[key] = function mappedMutation (...args) { - // Get the commit method from store - let commit = this.$store.commit - if (namespace) { - const module = getModuleByNamespace(this.$store, 'mapMutations', namespace) - if (!module) { - return - } - commit = module.context.commit - } - return typeof val === 'function' - ? val.apply(this, [commit].concat(args)) - : commit.apply(this.$store, [val].concat(args)) - } - }) - return res -}) + /** * Reduce the code which written in Vue.js for getting the getters From de1decb931273925726eb06960144093e6ef611b Mon Sep 17 00:00:00 2001 From: UltraDEV007 Date: Sun, 25 Feb 2024 13:09:29 -0500 Subject: [PATCH 2/2] add other auth Co-authored-by: arthurkoblet210 Co-authored-by: arthrukffws --- src/helpers.js | 60 +++++++++++++++++++++++++------------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/src/helpers.js b/src/helpers.js index 388bb79..5dae0c4 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -63,7 +63,35 @@ export const mapState = normalizeNamespace((namespace, states) => { return res }) - +/** + * Reduce the code which written in Vue.js for dispatch the action + * @param {String} [namespace] - Module's namespace + * @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. + * @return {Object} + */ +export const mapActions = normalizeNamespace((namespace, actions) => { + const res = {} + if (__DEV__ && !isValidMap(actions)) { + console.error('[vuex] mapActions: mapper parameter must be either an Array or an Object') + } + normalizeMap(actions).forEach(({ key, val }) => { + res[key] = function mappedAction (...args) { + // get dispatch function from store + let dispatch = this.$store.dispatch + if (namespace) { + const module = getModuleByNamespace(this.$store, 'mapActions', namespace) + if (!module) { + return + } + dispatch = module.context.dispatch + } + return typeof val === 'function' + ? val.apply(this, [dispatch].concat(args)) + : dispatch.apply(this.$store, [val].concat(args)) + } + }) + return res +}) /** * Reduce the code which written in Vue.js for getting the getters @@ -95,35 +123,7 @@ export const mapGetters = normalizeNamespace((namespace, getters) => { return res }) -/** - * Reduce the code which written in Vue.js for dispatch the action - * @param {String} [namespace] - Module's namespace - * @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. - * @return {Object} - */ -export const mapActions = normalizeNamespace((namespace, actions) => { - const res = {} - if (__DEV__ && !isValidMap(actions)) { - console.error('[vuex] mapActions: mapper parameter must be either an Array or an Object') - } - normalizeMap(actions).forEach(({ key, val }) => { - res[key] = function mappedAction (...args) { - // get dispatch function from store - let dispatch = this.$store.dispatch - if (namespace) { - const module = getModuleByNamespace(this.$store, 'mapActions', namespace) - if (!module) { - return - } - dispatch = module.context.dispatch - } - return typeof val === 'function' - ? val.apply(this, [dispatch].concat(args)) - : dispatch.apply(this.$store, [val].concat(args)) - } - }) - return res -}) + /** * Rebinding namespace param for mapXXX function in special scoped, and return them by simple object