Skip to content

Commit

Permalink
perf: decrease number of calls to translate all extensions only once (#…
Browse files Browse the repository at this point in the history
…1151)

* perf: decrease number of calls to translate all extensions only once
  • Loading branch information
ghiscoding committed Jan 27, 2024
1 parent 1250634 commit 97966a1
Show file tree
Hide file tree
Showing 5 changed files with 175 additions and 193 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"@lerna-lite/cli": "^3.2.1",
"@lerna-lite/publish": "^3.2.1",
"@types/jest": "^29.5.11",
"@types/node": "^20.11.6",
"@types/node": "^20.11.8",
"@typescript-eslint/eslint-plugin": "^6.19.1",
"@typescript-eslint/parser": "^6.19.1",
"cross-env": "^7.0.3",
Expand All @@ -61,7 +61,7 @@
"jsdom-global": "^3.0.2",
"moment-mini": "^2.29.4",
"npm-run-all2": "^6.1.1",
"pnpm": "^8.14.3",
"pnpm": "^8.15.0",
"rimraf": "^5.0.5",
"ts-jest": "^29.1.2",
"typescript": "^5.3.3"
Expand Down
10 changes: 5 additions & 5 deletions packages/aurelia-slickgrid/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@
"@aurelia/i18n": "latest",
"@aurelia/runtime": "latest",
"@aurelia/runtime-html": "latest",
"@slickgrid-universal/common": "~4.3.0",
"@slickgrid-universal/custom-footer-component": "~4.3.0",
"@slickgrid-universal/empty-warning-component": "~4.3.0",
"@slickgrid-universal/common": "~4.3.1",
"@slickgrid-universal/custom-footer-component": "~4.3.1",
"@slickgrid-universal/empty-warning-component": "~4.3.1",
"@slickgrid-universal/event-pub-sub": "~4.3.0",
"@slickgrid-universal/pagination-component": "~4.3.0",
"@slickgrid-universal/row-detail-view-plugin": "~4.3.0",
"@slickgrid-universal/pagination-component": "~4.3.1",
"@slickgrid-universal/row-detail-view-plugin": "~4.3.1",
"@slickgrid-universal/utils": "~4.3.0",
"dequal": "^2.0.3",
"dompurify": "^3.0.8",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -683,20 +683,16 @@ export class AureliaSlickgridCustomElement {
// translate some of them on first load, then on each language change
if (gridOptions.enableTranslate) {
this.extensionService.translateAllExtensions();
this.translateColumnHeaderTitleKeys();
this.translateColumnGroupKeys();
}

// on locale change, we have to manually translate the Headers, GridMenu
this.subscriptions.push(
this.globalEa.subscribe('i18n:locale:changed', () => {
this.globalEa.subscribe('i18n:locale:changed', (args: { oldLocale: string; newLocale: string; }) => {
// publish event of the same name that Slickgrid-Universal uses on a language change event
this._eventPubSubService.publish('onLanguageChange');

if (gridOptions.enableTranslate) {
this.extensionService.translateAllExtensions();
this.translateColumnHeaderTitleKeys();
this.translateColumnGroupKeys();
this.extensionService.translateAllExtensions(args.newLocale);
if (gridOptions.createPreHeaderPanel && !gridOptions.enableDraggableGrouping) {
this.groupingService.translateGroupingAndColSpan();
}
Expand Down Expand Up @@ -956,10 +952,6 @@ export class AureliaSlickgridCustomElement {
this._isDatasetInitialized = true;
}

if (dataset) {
this.grid.invalidate();
}

// display the Pagination component only after calling this refresh data first, we call it here so that if we preset pagination page number it will be shown correctly
this.showPagination = (this.gridOptions && (this.gridOptions.enablePagination || (this.gridOptions.backendServiceApi && this.gridOptions.enablePagination === undefined))) ? true : false;

Expand Down Expand Up @@ -1037,7 +1029,7 @@ export class AureliaSlickgridCustomElement {
}

if (this.gridOptions.enableTranslate) {
this.extensionService.translateColumnHeaders(false, newColumnDefinitions);
this.extensionService.translateColumnHeaders(undefined, newColumnDefinitions);
} else {
this.extensionService.renderColumnHeaders(newColumnDefinitions, true);
}
Expand Down Expand Up @@ -1486,16 +1478,6 @@ export class AureliaSlickgridCustomElement {
});
}

/** translate all columns (including hidden columns) */
protected translateColumnHeaderTitleKeys() {
this.extensionUtility.translateItems(this.sharedService.allColumns, 'nameKey', 'name');
}

/** translate all column groups (including hidden columns) */
protected translateColumnGroupKeys() {
this.extensionUtility.translateItems(this.sharedService.allColumns, 'columnGroupKey', 'columnGroup');
}

/**
* Update the "internalColumnEditor.collection" property.
* Since this is called after the async call resolves, the pointer will not be the same as the "column" argument passed.
Expand Down
24 changes: 12 additions & 12 deletions packages/demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,24 +47,24 @@
"@aurelia/router": "latest",
"@aurelia/runtime": "latest",
"@aurelia/runtime-html": "latest",
"@faker-js/faker": "^8.3.1",
"@faker-js/faker": "^8.4.0",
"@fnando/sparkline": "^0.3.10",
"@popperjs/core": "^2.11.8",
"@slickgrid-universal/common": "~4.3.0",
"@slickgrid-universal/composite-editor-component": "~4.3.0",
"@slickgrid-universal/custom-tooltip-plugin": "~4.3.0",
"@slickgrid-universal/excel-export": "~4.3.0",
"@slickgrid-universal/graphql": "~4.3.0",
"@slickgrid-universal/odata": "~4.3.0",
"@slickgrid-universal/row-detail-view-plugin": "~4.3.0",
"@slickgrid-universal/rxjs-observable": "~4.3.0",
"@slickgrid-universal/text-export": "~4.3.0",
"@slickgrid-universal/common": "latest",
"@slickgrid-universal/composite-editor-component": "latest",
"@slickgrid-universal/custom-tooltip-plugin": "latest",
"@slickgrid-universal/excel-export": "latest",
"@slickgrid-universal/graphql": "latest",
"@slickgrid-universal/odata": "latest",
"@slickgrid-universal/row-detail-view-plugin": "latest",
"@slickgrid-universal/rxjs-observable": "latest",
"@slickgrid-universal/text-export": "latest",
"aurelia": "latest",
"aurelia-slickgrid": "workspace:*",
"bootstrap": "^5.3.2",
"dompurify": "^3.0.8",
"flatpickr": "^4.6.13",
"i18next": "^23.7.17",
"i18next": "^23.7.20",
"i18next-fetch-backend": "^5.0.2",
"moment-mini": "^2.29.4",
"rxjs": "^7.8.1"
Expand All @@ -76,7 +76,7 @@
"@types/dompurify": "^3.0.5",
"@types/fnando__sparkline": "^0.3.7",
"@types/jest": "^29.5.11",
"@types/node": "^20.11.6",
"@types/node": "^20.11.8",
"@types/sortablejs": "^1.15.7",
"aurelia-polyfills": "^1.3.4",
"autoprefixer": "^10.4.17",
Expand Down

0 comments on commit 97966a1

Please sign in to comment.