Skip to content

Commit

Permalink
Debounce onChange calls to avoid unnecessary tool rebuilding
Browse files Browse the repository at this point in the history
  • Loading branch information
davelopez committed Oct 10, 2024
1 parent 865f924 commit e15b9f9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions client/src/components/Form/FormDisplay.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
</template>

<script>
import { debounce } from "underscore";
import Vue from "vue";
import FormInputs from "./FormInputs";
Expand Down Expand Up @@ -180,15 +181,15 @@ export default {
});
this.onCreateIndex();
},
onChange(refreshOnChange) {
onChange: debounce(function (refreshOnChange) {
this.onCreateIndex();
const params = this.buildFormData();
if (JSON.stringify(params) != JSON.stringify(this.formData)) {
this.formData = params;
this.resetErrors();
this.$emit("onChange", params, refreshOnChange);
}
},
}, 500),
onErrors() {
this.resetErrors();
if (this.errors) {
Expand Down
5 changes: 3 additions & 2 deletions client/src/components/Tool/ToolForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ import ToolEntryPoints from "components/ToolEntryPoints/ToolEntryPoints";
import { mapActions, mapState, storeToRefs } from "pinia";
import { useHistoryItemsStore } from "stores/historyItemsStore";
import { useJobStore } from "stores/jobStore";
import { debounce } from "underscore";
import { refreshContentsWrapper } from "utils/data";
import { canMutateHistory } from "@/api";
Expand Down Expand Up @@ -284,7 +285,7 @@ export default {
this.onUpdate();
}
},
onUpdate() {
onUpdate: debounce(function (e) {
this.disabled = true;
console.debug("ToolForm - Updating input parameters.", this.formData);
updateToolFormData(this.formConfig.id, this.currentVersion, this.history_id, this.formData)
Expand All @@ -294,7 +295,7 @@ export default {
.finally(() => {
this.disabled = false;
});
},
}, 500),
onChangeVersion(newVersion) {
this.requestTool(newVersion);
},
Expand Down

0 comments on commit e15b9f9

Please sign in to comment.