Skip to content

Commit

Permalink
Merge pull request #1386 from VisActor/refactor/setRecords-memory
Browse files Browse the repository at this point in the history
Refactor/set records memory
  • Loading branch information
fangsmile authored Mar 27, 2024
2 parents a1de579 + 608d195 commit 6a35e3d
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"comment": "refactor: setRecords clear reference object #1188\n\n",
"type": "none",
"packageName": "@visactor/vtable"
}
],
"packageName": "@visactor/vtable",
"email": "[email protected]"
}
13 changes: 9 additions & 4 deletions packages/vtable/examples/list/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const generatePersons = count => {
};

export function createTable() {
const records = generatePersons(10000);
const records = generatePersons(1000000);
const columns: VTable.ColumnsDefine = [
{
field: '',
Expand Down Expand Up @@ -203,9 +203,14 @@ export function createTable() {
tableInstance.on('change_cell_value', arg => {
console.log(arg);
});
// setTimeout(() => {
// tableInstance.addRecord({ id: 333 }, 6);
// }, 3000);
let count = 0;
const intervalId = setTimeout(() => {
count++;
tableInstance.updateOption(option);
if (count > 100) {
clearInterval(intervalId);
}
}, 3000);
// tableInstance.on('sort_click', args => {
// tableInstance.updateSortState(
// {
Expand Down
5 changes: 5 additions & 0 deletions packages/vtable/src/ListTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,11 @@ export class ListTable extends BaseTable implements ListTableAPI {
* @param sort
*/
setRecords(records: Array<any>, option?: { sortState?: SortState | SortState[] }): void {
// 释放事件 及 对象
this.internalProps.dataSource?.release();
// 过滤掉dataSource的引用
this.internalProps.releaseList = this.internalProps.releaseList?.filter((item: any) => !item.dataSourceObj);
this.internalProps.dataSource = null;
let sort: SortState | SortState[];
if (Array.isArray(option) || (option as any)?.order) {
//兼容之前第二个参数为sort的情况
Expand Down
12 changes: 10 additions & 2 deletions packages/vtable/src/core/BaseTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2170,7 +2170,11 @@ export abstract class BaseTable extends EventTarget implements BaseTableAPI {
*/
getBottomFrozenRowsHeight(): number {
if (this.bottomFrozenRowCount > 0) {
const height = this.getRowsHeight(this.rowCount - this.bottomFrozenRowCount, this.rowCount - 1);
// const height = this.getRowsHeight(this.rowCount - this.bottomFrozenRowCount, this.rowCount - 1);//替换成下面遍历获取高度,鉴于冻结数量有限。否则这里在初始化的时候ClipBodyGroupBeforeRenderContribution.drawShap就先走了这个计算,导致初始化时间加长,而后续计算行高列宽会清除这个计算结果,浪费了性能
let height = 0;
for (let row = this.rowCount - this.bottomFrozenRowCount; row <= this.rowCount - 1; row++) {
height += this.getRowHeight(row);
}
return height;
}
return 0;
Expand All @@ -2181,7 +2185,11 @@ export abstract class BaseTable extends EventTarget implements BaseTableAPI {
*/
getRightFrozenColsWidth(): number {
if (this.rightFrozenColCount > 0) {
const width = this.getColsWidth(this.colCount - this.rightFrozenColCount, this.colCount - 1);
// const width = this.getColsWidth(this.colCount - this.rightFrozenColCount, this.colCount - 1); // 同getBottomFrozenRowsHeight的原因
let width = 0;
for (let col = this.colCount - this.rightFrozenColCount; col <= this.colCount - 1; col++) {
width += this.getColWidth(col);
}
return width;
}
return 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ export class TableComponent {
this.frozenShadowLine.setAttributes({
visible: true,
x: colX,
height: this.table.getRowsHeight(0, this.table.rowCount - 1)
height: this.table.tableNoFrameHeight
});
}
}
Expand Down

0 comments on commit 6a35e3d

Please sign in to comment.