Skip to content

Commit

Permalink
Fix debounce rerender on multiple sbom trees
Browse files Browse the repository at this point in the history
  • Loading branch information
ulischulte committed Jul 10, 2024
1 parent 3621e6e commit f04e547
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@
</sba-input>
</sba-sticky-subnav>
</template>
<template v-for="sbomId in sboms" :key="sbomId">
<tree-graph
:instance="instance"
:sbom-id="sbomId"
:filter="filter"
></tree-graph>
</template>

<tree-graph
v-for="sbomId in sboms"
:key="sbomId"
:instance="instance"
:sbom-id="sbomId"
:filter="filter"
></tree-graph>
</sba-instance-section>
</template>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
</template>

<script lang="ts">
import { debounce } from 'lodash-es';
import { ref } from 'vue';
import Instance from '@/services/instance';
Expand Down Expand Up @@ -42,21 +41,33 @@ export default {
rootNode: null,
}),
watch: {
filter: {
deep: true,
handler: debounce(function () {
if (!this.filter.trim()) {
this.renderTree(this.dependencies);
} else {
this.updateTree();
}
}, 1000),
},
filter: 'debounceRerender',
},
created() {
this.fetchSbomDependencies(this.sbomId);
},
methods: {
debounceRerender(newVal) {
this.debounce(function () {
if (!newVal.trim()) {
this.renderTree(this.dependencies);
} else {
this.updateTree();
}
}, 1000);
},
// lodash debounce won't work with multiple invocations of the same function on different dependencyTrees
debounce(func, wait) {
let timeout;
// eslint-disable-next-line @typescript-eslint/no-this-alias
const context = this,
args = arguments;
clearTimeout(timeout);
timeout = setTimeout(function () {
timeout = null;
func.apply(context, args);
}, wait);
},
async fetchSbomDependencies(sbomId) {
this.error = null;
try {
Expand Down

0 comments on commit f04e547

Please sign in to comment.