Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(perf): 去除初始化时,多余的 drilldown 渲染链路 #2446

Merged
merged 3 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion packages/s2-core/__tests__/unit/sheet-type/pivot-sheet-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ describe('PivotSheet Tests', () => {

const clearDrillDownDataSpy = jest
.spyOn(s2.dataSet, 'clearDrillDownData' as any)
.mockImplementation(() => {});
.mockImplementation(() => true);

s2.clearDrillDownData();

Expand All @@ -722,6 +722,22 @@ describe('PivotSheet Tests', () => {
renderSpy.mockRestore();
});

test(`shouldn't rerender without drill down data`, () => {
const renderSpy = jest.spyOn(s2, 'render').mockImplementation(() => {});
wjgogogo marked this conversation as resolved.
Show resolved Hide resolved

const clearDrillDownDataSpy = jest
.spyOn(s2.dataSet, 'clearDrillDownData' as any)
.mockImplementation(() => false);

s2.clearDrillDownData();

expect(clearDrillDownDataSpy).toHaveBeenCalledTimes(1);
// rerender
expect(renderSpy).toHaveBeenCalledTimes(0);

renderSpy.mockRestore();
});

test('should get extra field text', () => {
const pivotSheet = new PivotSheet(
container,
Expand Down
3 changes: 2 additions & 1 deletion packages/s2-core/src/data-set/pivot-data-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export class PivotDataSet extends BaseDataSet {
const store = this.spreadsheet.store;
const idPathMap = store.get('drillDownIdPathMap');
if (!idPathMap) {
return;
return false;
}
const drillDownDataCache = store.get(
'drillDownDataCache',
Expand Down Expand Up @@ -225,6 +225,7 @@ export class PivotDataSet extends BaseDataSet {
}

store.set('drillDownIdPathMap', idPathMap);
return true;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/s2-core/src/sheet-type/pivot-sheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ export class PivotSheet extends SpreadSheet {

public clearDrillDownData(rowNodeId?: string, preventRender?: boolean) {
if (this.dataSet instanceof PivotDataSet) {
this.dataSet.clearDrillDownData(rowNodeId);
if (!preventRender) {
const cleaned = this.dataSet.clearDrillDownData(rowNodeId);
if (cleaned && !preventRender) {
// 重置当前交互
this.interaction.reset();
this.render(false);
Expand Down
Loading