Skip to content

Commit c89f95e

Browse files
authored
fix(modules): adds clean-up after before module deletion (#481)
Updates module removal to use an action which deletes input links before a module's removal
1 parent 084df8b commit c89f95e

3 files changed

Lines changed: 34 additions & 3 deletions

File tree

src/application/worker/store/modules/modules.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,36 @@ const actions = {
475475
}
476476

477477
return;
478+
},
479+
480+
async removeActiveModule({ commit }, { moduleId, writeToSwap }) {
481+
const writeTo = writeToSwap ? swap : state;
482+
483+
const module = writeTo.active[moduleId];
484+
const { meta } = module;
485+
486+
if (!module) {
487+
throw new Error(`No module with id "${moduleId}" found`);
488+
}
489+
490+
const metaInputIds = [
491+
meta.alphaInputId,
492+
meta.compositeOperationInputId,
493+
meta.enabledInputId
494+
];
495+
const moduleProperties = Object.values(module.$props).map(prop => prop.id);
496+
const inputIds = [...moduleProperties, ...metaInputIds];
497+
498+
for (let i = 0, len = inputIds.length; i < len; i++) {
499+
const inputId = inputIds[i];
500+
501+
await store.dispatch("inputs/removeInputLink", {
502+
inputId,
503+
writeToSwap
504+
});
505+
}
506+
507+
commit("REMOVE_ACTIVE_MODULE", { moduleId, writeToSwap });
478508
}
479509
};
480510

src/components/GalleryItem.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,11 @@ export default {
7777
window.dispatchEvent(new Event("resize"));
7878
},
7979
80-
beforeDestroy() {
81-
this.$modV.store.commit("modules/REMOVE_ACTIVE_MODULE", {
80+
async beforeDestroy() {
81+
await this.$modV.store.dispatch("modules/removeActiveModule", {
8282
moduleId: this.id
8383
});
84+
8485
this.$modV.store.commit("outputs/REMOVE_AUXILLARY", this.outputId);
8586
this.$modV.store.commit("groups/REMOVE_MODULE_FROM_GROUP", {
8687
groupId: this.groupId,

src/components/Group.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ export default {
478478
groupId
479479
});
480480
481-
this.$modV.store.commit("modules/REMOVE_ACTIVE_MODULE", {
481+
this.$modV.store.dispatch("modules/removeActiveModule", {
482482
moduleId
483483
});
484484
},

0 commit comments

Comments
 (0)