Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-01-13 18:07:53 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-01-13 18:07:53 +0300
commita5ab3467a705b62911feacc3cf627fdbb00aa198 (patch)
tree65143ce13405efccb922fc428624ad57c38b6efa /app/assets/javascripts/vuex_shared
parenteb30dd6e28f6fc9eb8021d205f6ed84511f001e2 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/assets/javascripts/vuex_shared')
-rw-r--r--app/assets/javascripts/vuex_shared/bindings.js26
1 files changed, 23 insertions, 3 deletions
diff --git a/app/assets/javascripts/vuex_shared/bindings.js b/app/assets/javascripts/vuex_shared/bindings.js
index 51035ebc8a8..817a90f8149 100644
--- a/app/assets/javascripts/vuex_shared/bindings.js
+++ b/app/assets/javascripts/vuex_shared/bindings.js
@@ -1,9 +1,29 @@
-export const mapComputed = (root, updateFn, list) => {
+/**
+ * Returns computed properties two way bound to vuex
+ *
+ * @param {(string[]|Object[])} list - list of string matching state keys or list objects
+ * @param {string} list[].key - the key matching the key present in the vuex state
+ * @param {string} list[].getter - the name of the getter, leave it empty to not use a getter
+ * @param {string} list[].updateFn - the name of the action, leave it empty to use the default action
+ * @param {string} defaultUpdateFn - the default function to dispatch
+ * @param {string} root - the key of the state where to search fo they keys described in list
+ * @returns {Object} a dictionary with all the computed properties generated
+ */
+export const mapComputed = (list, defaultUpdateFn, root) => {
const result = {};
- list.forEach(key => {
+ list.forEach(item => {
+ const [getter, key, updateFn] =
+ typeof item === 'string'
+ ? [false, item, defaultUpdateFn]
+ : [item.getter, item.key, item.updateFn || defaultUpdateFn];
result[key] = {
get() {
- return this.$store.state[root][key];
+ if (getter) {
+ return this.$store.getters[getter];
+ } else if (root) {
+ return this.$store.state[root][key];
+ }
+ return this.$store.state[key];
},
set(value) {
this.$store.dispatch(updateFn, { [key]: value });