Skip to content

Commit

Permalink
fix(swap): properly set default swap structure when finished swapping
Browse files Browse the repository at this point in the history
fixes #765
  • Loading branch information
2xAA committed Sep 21, 2022
1 parent 0000d7a commit 4545080
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 23 deletions.
10 changes: 3 additions & 7 deletions src/application/worker/index.worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,13 +341,9 @@ async function start() {
}
}

store.commit("groups/SWAP", {});
store.commit("modules/SWAP", {});
store.commit("inputs/SWAP", {});

store.commit("groups/CLEAR_SWAP", {});
store.commit("modules/CLEAR_SWAP", {});
store.commit("inputs/CLEAR_SWAP", {});
store.commit("groups/SWAP");
store.commit("modules/SWAP");
store.commit("inputs/SWAP");

return;
}
Expand Down
10 changes: 7 additions & 3 deletions src/application/worker/store/modules/groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,12 @@ import { applyExpression } from "../../../utils/apply-expression";
* };
*/

const state = { groups: [] };
const swap = { groups: [] };
function getDefaultState() {
return { groups: [] };
}

const state = getDefaultState();
const swap = getDefaultState();

// Any keys marked false or arrays with keys given
// will not be moved from the base state when swapped
Expand Down Expand Up @@ -358,7 +362,7 @@ const mutations = {
}
},

SWAP: SWAP(swap, () => ({ groups: [] }), sharedPropertyRestrictions)
SWAP: SWAP(swap, getDefaultState, sharedPropertyRestrictions)
};

export default {
Expand Down
24 changes: 11 additions & 13 deletions src/application/worker/store/modules/modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,17 @@ const sharedPropertyRestrictions = {
metaQueue: true // will move
};

const state = {
registered: {},
active: {},
propQueue: {},
metaQueue: {}
};
function getDefaultState() {
return {
registered: {},
active: {},
propQueue: {},
metaQueue: {}
};
}

const swap = {
registered: {},
active: {},
propQueue: {},
metaQueue: {}
};
const state = getDefaultState();
const swap = getDefaultState();

// this function either creates module properties from an existing module
// (e.g. loading a preset) or initialises the default value
Expand Down Expand Up @@ -721,7 +719,7 @@ const mutations = {
}
},

SWAP: SWAP(swap, () => ({}), sharedPropertyRestrictions)
SWAP: SWAP(swap, getDefaultState, sharedPropertyRestrictions)
};

export default {
Expand Down

0 comments on commit 4545080

Please sign in to comment.