Skip to content

Commit 3291b16

Browse files
committed
fixup! chore(table): update tabulator to 6
1 parent d4a6243 commit 3291b16

File tree

1 file changed

+43
-7
lines changed

1 file changed

+43
-7
lines changed

src/components/table/table.tsx

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,8 @@ export class Table {
238238
private columnFactory: ColumnDefinitionFactory;
239239
private firstRequest: boolean;
240240
private initialized = false;
241+
private destroyed = false;
242+
private resizeObserver: ResizeObserver;
241243
private currentSorting: ColumnSorter[];
242244
private tableSelection: TableSelection;
243245
private shouldSort = false;
@@ -265,10 +267,24 @@ export class Table {
265267
}
266268

267269
public componentDidLoad() {
270+
this.destroyed = false;
268271
this.init();
269272
}
270273

271274
public disconnectedCallback() {
275+
this.destroyed = true;
276+
this.initialized = false;
277+
278+
if (this.resizeObserver) {
279+
this.resizeObserver.disconnect();
280+
this.resizeObserver = null;
281+
}
282+
283+
if (this.tabulator) {
284+
this.tabulator.destroy();
285+
this.tabulator = null;
286+
}
287+
272288
this.pool.clear();
273289
}
274290

@@ -514,15 +530,19 @@ export class Table {
514530
return;
515531
}
516532

517-
const observer = new ResizeObserver(() => {
533+
this.resizeObserver = new ResizeObserver(() => {
518534
requestAnimationFrame(() => {
535+
if (this.destroyed) {
536+
return;
537+
}
538+
519539
this.tabulator = this.createTabulator(table);
520540
this.setSelection();
521-
observer.unobserve(table);
522-
observer.disconnect();
541+
this.resizeObserver?.unobserve(table);
542+
this.resizeObserver?.disconnect();
523543
});
524544
});
525-
observer.observe(table);
545+
this.resizeObserver.observe(table);
526546
}
527547

528548
private createTabulator(table: HTMLElement): Tabulator {
@@ -533,10 +553,14 @@ export class Table {
533553
tabulator.on('columnMoved', this.handleMoveColumn);
534554
tabulator.on('renderComplete', this.handleRenderComplete);
535555
tabulator.on('tableBuilt', () => {
556+
if (this.destroyed) {
557+
tabulator.destroy();
558+
559+
return;
560+
}
561+
536562
this.initialized = true;
537-
if (this.isRemoteMode()) {
538-
this.tabulator.setData('https://localhost');
539-
} else {
563+
if (!this.isRemoteMode()) {
540564
this.updateData(this.data, []);
541565
}
542566
});
@@ -684,11 +708,19 @@ export class Table {
684708
*
685709
*/
686710
private handleAjaxRequesting() {
711+
if (this.destroyed) {
712+
return false;
713+
}
714+
687715
const abortRequest = this.firstRequest && !!this.data?.length;
688716
this.firstRequest = false;
689717

690718
if (abortRequest) {
691719
setTimeout(() => {
720+
if (this.destroyed || !this.tabulator) {
721+
return;
722+
}
723+
692724
this.updateMaxPage();
693725
this.tabulator.replaceData(this.data);
694726
});
@@ -713,6 +745,10 @@ export class Table {
713745
}
714746

715747
private requestData(_, __, params: any): Promise<object> {
748+
if (this.destroyed) {
749+
return Promise.reject();
750+
}
751+
716752
const sorters = params.sorters;
717753
const currentPage = params.page;
718754

0 commit comments

Comments
 (0)