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-04-07 21:09:19 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-04-07 21:09:19 +0300
commit3290d46655f07d7ae3dca788d6df9f326972ffd8 (patch)
tree0d24713e1592cdd3583257f14a52d46a22539ed1 /app/assets/javascripts/vue_shared
parentc6b3ec3f56fa32a0e0ed3de0d0878d25f1adaddf (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/assets/javascripts/vue_shared')
-rw-r--r--app/assets/javascripts/vue_shared/components/local_storage_sync.vue39
1 files changed, 39 insertions, 0 deletions
diff --git a/app/assets/javascripts/vue_shared/components/local_storage_sync.vue b/app/assets/javascripts/vue_shared/components/local_storage_sync.vue
new file mode 100644
index 00000000000..b5d6b872547
--- /dev/null
+++ b/app/assets/javascripts/vue_shared/components/local_storage_sync.vue
@@ -0,0 +1,39 @@
+<script>
+export default {
+ props: {
+ storageKey: {
+ type: String,
+ required: true,
+ },
+ value: {
+ type: String,
+ required: false,
+ default: '',
+ },
+ },
+ watch: {
+ value(newVal) {
+ this.saveValue(newVal);
+ },
+ },
+ mounted() {
+ // On mount, trigger update if we actually have a localStorageValue
+ const value = this.getValue();
+
+ if (value && this.value !== value) {
+ this.$emit('input', value);
+ }
+ },
+ methods: {
+ getValue() {
+ return localStorage.getItem(this.storageKey);
+ },
+ saveValue(val) {
+ localStorage.setItem(this.storageKey, val);
+ },
+ },
+ render() {
+ return this.$slots.default;
+ },
+};
+</script>