Skip to content

Commit

Permalink
chore: simplify fetch
Browse files Browse the repository at this point in the history
 - use await to flatten code
 - must await dispatch otherwise there's a race for the background
   updating correctly
  • Loading branch information
yanfali committed Nov 1, 2024
1 parent 1de7f72 commit 12ab1c5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 76 deletions.
19 changes: 9 additions & 10 deletions src/store/modules/app/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const actions = {
commit('setKeyboard', keyboard);
const oldLayout = state.layout || '';
commit('setLayout', undefined);
dispatch('loadLayouts');
await dispatch('loadLayouts');
let nextLayout = getPreferredLayout(state.layouts);
console.info(getPreferredLayout(state.layouts));
if (oldLayout && !isUndefined(state.layouts[oldLayout])) {
Expand Down Expand Up @@ -122,16 +122,15 @@ const actions = {
});
return p;
}
await fetch(`${backend_keyboards_url}/${state.keyboard}/info.json`).then(
async (resp) => {
if (resp.ok) {
const data = await resp.json();
commit('setKeyboardMeta', data);
commit('processLayouts', data);
return resp;
}
}
const resp = await fetch(
`${backend_keyboards_url}/${state.keyboard}/info.json`
);
if (resp.ok) {
const data = await resp.json();
commit('setKeyboardMeta', data);
commit('processLayouts', data);
return resp;
}
},
saveConfiguratorSettings({ state }) {
localStorageSet(
Expand Down
1 change: 0 additions & 1 deletion src/store/modules/app/mutations.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ const mutations = {
state.snowflakes = !state.snowflakes;
},
setKeyboardMeta(state, data) {
debugger;
state.keyboardMeta = data?.keyboards ? data.keyboards : {};
}
};
Expand Down
65 changes: 0 additions & 65 deletions src/store/tester.js

This file was deleted.

0 comments on commit 12ab1c5

Please sign in to comment.