Skip to content

Commit

Permalink
Merge pull request #397 from achirus-code/main
Browse files Browse the repository at this point in the history
Add debouncing to resize event to optimize resize performance
  • Loading branch information
johanneswilm authored Oct 7, 2024
2 parents 5b5b558 + c140f64 commit 9ba5c04
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/datatable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {Rows} from "./rows"
import {Columns} from "./columns"
import {defaultConfig} from "./config"
import {createVirtualPagerDOM} from "./virtual_pager_dom"
import {debounce} from "./editing/helpers"


export class DataTable {
Expand Down Expand Up @@ -658,16 +659,15 @@ export class DataTable {
}

/**
* execute on resize
* execute on resize and debounce to avoid multiple calls
*/
_onResize() {
_onResize = debounce(() => {
this._rect = this.containerDOM.getBoundingClientRect()
if (!this._rect.width) {
// No longer shown, likely no longer part of DOM. Give up.
return
}
this.update(true)
}
}, 100)

/**
* Destroy the instance
Expand Down

0 comments on commit 9ba5c04

Please sign in to comment.