Skip to content
This repository was archived by the owner on Jun 1, 2025. It is now read-only.

Commit 21a5016

Browse files
committed
perf: decrease number of calls to translate all extensions only once
- this PR requires and follows Slickgrid-Universal ghiscoding/slickgrid-universal#1359
1 parent 6b18b14 commit 21a5016

File tree

2 files changed

+9
-24
lines changed

2 files changed

+9
-24
lines changed

src/app/modules/angular-slickgrid/components/__tests__/angular-slickgrid.component.spec.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,11 +1042,12 @@ describe('Angular-Slickgrid Custom Component instantiated via Constructor', () =
10421042
const refreshSpy = jest.spyOn(component, 'refreshGridData');
10431043

10441044
const mockData = [{ firstName: 'John', lastName: 'Doe' }, { firstName: 'Jane', lastName: 'Smith' }];
1045-
jest.spyOn(mockDataView, 'getItems').mockReturnValue(mockData);
1045+
jest.spyOn(mockDataView, 'getItems').mockReturnValueOnce(mockData);
10461046
component.gridOptions = {
10471047
enablePagination: true,
10481048
presets: { pagination: { pageSize: 2, pageNumber: expectedPageNumber } }
10491049
};
1050+
component.paginationOptions = undefined;
10501051
component.paginationOptions = { pageSize: 2, pageNumber: 2, pageSizes: [2, 10, 25, 50], totalItems: 100 };
10511052

10521053
component.dataset = mockData;
@@ -1163,7 +1164,7 @@ describe('Angular-Slickgrid Custom Component instantiated via Constructor', () =
11631164
component.gridOptions.backendServiceApi!.internalPostProcess!({ data: { notUsers: { nodes: [{ firstName: 'John' }], totalCount: 2 } } } as GraphqlPaginatedResult);
11641165

11651166
expect(spy).not.toHaveBeenCalled();
1166-
// expect(component.dataset).toEqual([]);
1167+
expect(component.dataset).toEqual([]);
11671168
});
11681169

11691170
it('should invoke "updateFilters" method with filters returned from "getColumnFilters" of the Filter Service when there is no Presets defined', () => {
@@ -1949,8 +1950,7 @@ describe('Angular-Slickgrid Custom Component instantiated via Constructor', () =
19491950
expect(footerSpy).toHaveBeenCalledWith(expectation);
19501951
});
19511952

1952-
it.skip('should have custom footer with metrics when the DataView "onSetItemsCalled" event is triggered', () => {
1953-
const invalidateSpy = jest.spyOn(mockGrid, 'invalidate');
1953+
it('should have custom footer with metrics when the DataView "onSetItemsCalled" event is triggered', () => {
19541954
const expectation = {
19551955
startTime: expect.toBeDate(),
19561956
endTime: expect.toBeDate(),
@@ -1964,7 +1964,6 @@ describe('Angular-Slickgrid Custom Component instantiated via Constructor', () =
19641964
const footerSpy = jest.spyOn(component.slickFooter!, 'metrics', 'set');
19651965
mockDataView.onSetItemsCalled.notify({ idProperty: 'id', itemCount: 0 });
19661966

1967-
expect(invalidateSpy).toHaveBeenCalled();
19681967
expect(footerSpy).toHaveBeenCalledWith(expectation);
19691968
expect(component.metrics).toEqual(expectation);
19701969
});

src/app/modules/angular-slickgrid/components/angular-slickgrid.component.ts

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ import { ContainerService } from '../services/container.service';
9595
]
9696
})
9797
export class AngularSlickgridComponent<TData = any> implements AfterViewInit, OnDestroy {
98-
protected _dataset?: any[] | null;
98+
protected _dataset?: TData[] | null;
9999
protected _columnDefinitions!: Column[];
100100
protected _currentDatasetLength = 0;
101101
protected _eventHandler: SlickEventHandler = new SlickEventHandler();
@@ -358,7 +358,7 @@ export class AngularSlickgridComponent<TData = any> implements AfterViewInit, On
358358
this._isGridInitialized = true;
359359

360360
// recheck the empty warning message after grid is shown so that it works in every use case
361-
if (this.gridOptions && this.gridOptions.enableEmptyDataWarningMessage && Array.isArray(this.dataset)) {
361+
if (this.gridOptions?.enableEmptyDataWarningMessage && Array.isArray(this.dataset)) {
362362
const finalTotalCount = this.dataset.length;
363363
this.displayEmptyDataWarning(finalTotalCount < 1);
364364
}
@@ -789,7 +789,7 @@ export class AngularSlickgridComponent<TData = any> implements AfterViewInit, On
789789
newColumnDefinitions = this.swapInternalEditorToSlickGridFactoryEditor(newColumnDefinitions);
790790

791791
if (this.gridOptions.enableTranslate) {
792-
this.extensionService.translateColumnHeaders(false, newColumnDefinitions);
792+
this.extensionService.translateColumnHeaders(undefined, newColumnDefinitions);
793793
} else {
794794
this.extensionService.renderColumnHeaders(newColumnDefinitions, true);
795795
}
@@ -835,19 +835,15 @@ export class AngularSlickgridComponent<TData = any> implements AfterViewInit, On
835835
// translate some of them on first load, then on each language change
836836
if (gridOptions.enableTranslate) {
837837
this.extensionService.translateAllExtensions();
838-
this.translateColumnHeaderTitleKeys();
839-
this.translateColumnGroupKeys();
840838
}
841839

842840
this.subscriptions.push(
843-
this.translate.onLangChange.subscribe(() => {
841+
this.translate.onLangChange.subscribe(({ lang }) => {
844842
// publish event of the same name that Slickgrid-Universal uses on a language change event
845843
this._eventPubSubService.publish('onLanguageChange');
846844

847845
if (gridOptions.enableTranslate) {
848-
this.extensionService.translateAllExtensions();
849-
this.translateColumnHeaderTitleKeys();
850-
this.translateColumnGroupKeys();
846+
this.extensionService.translateAllExtensions(lang);
851847
if (gridOptions.createPreHeaderPanel && !gridOptions.enableDraggableGrouping) {
852848
this.groupingService.translateGroupingAndColSpan();
853849
}
@@ -1407,16 +1403,6 @@ export class AngularSlickgridComponent<TData = any> implements AfterViewInit, On
14071403
});
14081404
}
14091405

1410-
protected translateColumnHeaderTitleKeys() {
1411-
// translate all columns (including hidden columns)
1412-
this.extensionUtility.translateItems(this.sharedService.allColumns, 'nameKey', 'name');
1413-
}
1414-
1415-
protected translateColumnGroupKeys() {
1416-
// translate all column groups (including hidden columns)
1417-
this.extensionUtility.translateItems(this.sharedService.allColumns, 'columnGroupKey', 'columnGroup');
1418-
}
1419-
14201406
/**
14211407
* Update the "internalColumnEditor.collection" property.
14221408
* Since this is called after the async call resolves, the pointer will not be the same as the "column" argument passed.

0 commit comments

Comments
 (0)