changed from window resize event, to element ResizeObserver for more accurate tracking of tree size (#4132)

This commit is contained in:
Jamie V
2021-08-18 16:38:48 -07:00
committed by GitHub
parent 9f48764210
commit a99ce7733c

View File

@ -226,18 +226,21 @@ export default {
}, },
created() { created() {
this.getSearchResults = _.debounce(this.getSearchResults, 400); this.getSearchResults = _.debounce(this.getSearchResults, 400);
this.handleWindowResize = _.debounce(this.handleWindowResize, 500); this.handleTreeResize = _.debounce(this.handleTreeResize, 300);
this.scrollEndEvent = _.debounce(this.scrollEndEvent, 100); this.scrollEndEvent = _.debounce(this.scrollEndEvent, 100);
}, },
destroyed() { destroyed() {
window.removeEventListener('resize', this.handleWindowResize); if (this.treeResizeObserver) {
this.treeResizeObserver.disconnect();
}
}, },
methods: { methods: {
async initialize() { async initialize() {
this.isLoading = true; this.isLoading = true;
this.openmct.$injector.get('searchService'); this.openmct.$injector.get('searchService');
this.getSavedOpenItems(); this.getSavedOpenItems();
window.addEventListener('resize', this.handleWindowResize); this.treeResizeObserver = new ResizeObserver(this.handleTreeResize);
this.treeResizeObserver.observe(this.$el);
await this.calculateHeights(); await this.calculateHeights();
@ -710,7 +713,7 @@ export default {
setSavedOpenItems() { setSavedOpenItems() {
localStorage.setItem(LOCAL_STORAGE_KEY__TREE_EXPANDED, JSON.stringify(this.openTreeItems)); localStorage.setItem(LOCAL_STORAGE_KEY__TREE_EXPANDED, JSON.stringify(this.openTreeItems));
}, },
handleWindowResize() { handleTreeResize() {
this.calculateHeights(); this.calculateHeights();
} }
} }