Skip to content

Commit

Permalink
Clean up some $store references (#656)
Browse files Browse the repository at this point in the history
  • Loading branch information
yanfali authored Feb 13, 2020
1 parent 4ac6ec1 commit 23db825
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions src/components/ControllerTop.vue
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,12 @@ export default {
name: 'ControllerTop',
computed: {
...mapGetters('keymap', ['isDirty']),
...mapGetters('app', ['exportKeymapName']),
...mapState('app', [
'keyboard',
'keyboards',
'layouts',
'layout',
'configuratorSettings',
'compileDisabled'
]),
Expand All @@ -121,9 +123,11 @@ export default {
if (
!confirm(clearKeymapTemplate({ action: 'change your keyboard' }))
) {
var old = this.$store.state.app.keyboard;
this.$store.commit('app/setKeyboard', ''); // force a refresh
Vue.nextTick(this.$store.commit('app/setKeyboard', old));
var old = this.keyboard;
this.setKeyboard(''); // force a refresh
Vue.nextTick(() => {
this.setKeyboard(old);
});
return false;
}
}
Expand All @@ -139,14 +143,13 @@ export default {
set(value) {
if (this.isDirty) {
if (!confirm(clearKeymapTemplate({ action: 'change your layout' }))) {
var old = this.$store.state.app.layout;
const setLayout = this.setLayout;
setLayout(''); // force a refresh
Vue.nextTick(() => setLayout(old));
const old = this.layout;
this.setLayout(''); // force a refresh
Vue.nextTick(() => this.setLayout(old));
return false;
}
}
this.$store.commit('keymap/clear');
this.clear();
this.updateLayout({ target: { value } });
}
},
Expand Down Expand Up @@ -200,14 +203,17 @@ export default {
}
},
methods: {
...mapMutations('keymap', ['resizeConfig']),
...mapMutations('keymap', ['resizeConfig', 'clear']),
...mapMutations('app', [
'setLayout',
'stopListening',
'startListening',
'previewRequested'
'previewRequested',
'setKeyboard',
'setKeymapName'
]),
...mapActions('app', [
'changeKeyboard',
'fetchKeyboards',
'loadDefaultKeymap',
'setFavoriteKeyboard'
Expand Down Expand Up @@ -309,9 +315,7 @@ export default {
// ignore initial load keyboard selection event if it's default
this.firstRun = false;
}
return this.$store
.dispatch('app/changeKeyboard', newKeyboard)
.then(this.postUpdateKeyboard);
return this.changeKeyboard(newKeyboard).then(this.postUpdateKeyboard);
},
favKeyboard() {
if (this.keyboard === this.configuratorSettings.favoriteKeyboard) {
Expand All @@ -328,6 +332,7 @@ export default {
})
.catch(err => {
if (err.name !== 'NavigationDuplicated') {
// ignore this harmless error otherwise report
throw err;
}
});
Expand All @@ -352,11 +357,11 @@ export default {
},
updateKeymapName(newKeymapName) {
this.keymapName = newKeymapName;
this.$store.commit('app/setKeymapName', newKeymapName);
this.setKeymapName(newKeymapName);
},
compile() {
let keymapName = this.realKeymapName;
let _keymapName = this.$store.getters['app/exportKeymapName'];
let _keymapName = this.exportKeymapName;
// TODO extract this name function to the store
keymapName =
keymapName === ''
Expand Down Expand Up @@ -397,11 +402,9 @@ export default {
};
},
mounted() {
console.info('mounted start');
this.initializeKeyboards().then(() => {
this.loadDefault(true);
});
console.info('mounted end');
}
};
</script>
Expand Down

0 comments on commit 23db825

Please sign in to comment.