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

Commit 2724c97

Browse files
committed
fix: registered external resouces should keep singleton ref
- external resources can be provided through the grid options, but these options are sometime deep copied and that might have the side effect of losing the singleton ref of the instantiate services/resources, instead we can simply keep these singleton refs before any grid options merge can happen and that is in the constructor before the grid initializes and before the grid options are merged and sometime deep copied with global options
1 parent 567f47b commit 2724c97

15 files changed

+113
-81
lines changed

src/app/examples/grid-clientside.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ export class GridClientSideComponent implements OnInit {
196196
{ columnId: 'complete', direction: 'ASC' }
197197
],
198198
},
199-
registerExternalResources: [new ExcelExportService()],
199+
externalResources: [new ExcelExportService()],
200200
};
201201

202202
// mock a dataset

src/app/examples/grid-colspan.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export class GridColspanComponent implements OnInit {
6868
excelExportOptions: {
6969
exportWithFormatter: false
7070
},
71-
registerExternalResources: [new ExcelExportService()],
71+
externalResources: [new ExcelExportService()],
7272
};
7373

7474
this.dataset1 = this.getData(500);
@@ -100,7 +100,7 @@ export class GridColspanComponent implements OnInit {
100100
excelExportOptions: {
101101
exportWithFormatter: false
102102
},
103-
registerExternalResources: [new ExcelExportService()],
103+
externalResources: [new ExcelExportService()],
104104
};
105105

106106
this.dataset2 = this.getData(500);

src/app/examples/grid-composite-editor.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ export class GridCompositeEditorComponent implements OnInit {
394394
excelExportOptions: {
395395
exportWithFormatter: false
396396
},
397-
registerExternalResources: [new ExcelExportService(), this.compositeEditorInstance],
397+
externalResources: [new ExcelExportService(), this.compositeEditorInstance],
398398
enableFiltering: true,
399399
rowSelectionOptions: {
400400
// True (Single Selection), False (Multiple Selections)

src/app/examples/grid-contextmenu.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ export class GridContextMenuComponent implements OnInit, OnDestroy {
297297
columnHeaderStyle: { font: { bold: true, italic: true } }
298298
},
299299
i18n: this.translate,
300-
registerExternalResources: [new ExcelExportService()],
300+
externalResources: [new ExcelExportService()],
301301

302302
enableContextMenu: true,
303303
enableCellMenu: true,

src/app/examples/grid-custom-tooltip.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ export class GridCustomTooltipComponent implements OnInit {
323323
exportWithFormatter: true
324324
},
325325
// Custom Tooltip options can be defined in a Column or Grid Options or a mixed of both (first options found wins)
326-
registerExternalResources: [new SlickCustomTooltip(), new ExcelExportService()],
326+
externalResources: [new SlickCustomTooltip(), new ExcelExportService()],
327327
customTooltip: {
328328
formatter: this.tooltipFormatter.bind(this) as Formatter,
329329
headerFormatter: this.headerFormatter,

src/app/examples/grid-draggrouping.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ export class GridDraggableGroupingComponent implements OnInit {
244244
enableTextExport: true,
245245
enableExcelExport: true,
246246
excelExportOptions: { sanitizeDataExport: true },
247-
registerExternalResources: [this.excelExportService, this.textExportService],
247+
externalResources: [this.excelExportService, this.textExportService],
248248
};
249249

250250
this.loadData(500);

src/app/examples/grid-graphql.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ export class GridGraphqlComponent implements OnInit, OnDestroy {
276276
setTimeout(() => {
277277
this.graphqlQuery = this.angularGrid.backendService!.buildQuery();
278278
if (this.isWithCursor) {
279-
// When using cursor pagination, the pagination service needs to updated with the PageInfo data from the latest request
279+
// When using cursor pagination, the pagination service needs to be updated with the PageInfo data from the latest request
280280
// This might be done automatically if using a framework specific slickgrid library
281281
// Note because of this timeout, this may cause race conditions with rapid clicks!
282282
this.angularGrid?.paginationService?.setCursorPageInfo((mockedResult.data[GRAPHQL_QUERY_DATASET_NAME].pageInfo));

src/app/examples/grid-grouping.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ export class GridGroupingComponent implements OnInit {
165165
},
166166
excelExportOptions: { sanitizeDataExport: true },
167167
textExportOptions: { sanitizeDataExport: true },
168-
registerExternalResources: [this.excelExportService, this.textExportService],
168+
externalResources: [this.excelExportService, this.textExportService],
169169
};
170170

171171
this.loadData(500);

src/app/examples/grid-localization.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ export class GridLocalizationComponent implements OnInit, OnDestroy {
202202
exportWithFormatter: true,
203203
sanitizeDataExport: true
204204
},
205-
registerExternalResources: [this.excelExportService, this.textExportService],
205+
externalResources: [this.excelExportService, this.textExportService],
206206
};
207207

208208
this.loadData(NB_ITEMS);

src/app/examples/grid-range.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ export class GridRangeComponent implements OnInit, OnDestroy {
184184
{ columnId: 'duration', direction: 'ASC' },
185185
],
186186
},
187-
registerExternalResources: [new SlickCustomTooltip(), new ExcelExportService()],
187+
externalResources: [new SlickCustomTooltip(), new ExcelExportService()],
188188
};
189189

190190
// mock a dataset

src/app/examples/grid-resize-by-content.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ export class GridResizeByContentComponent implements OnInit {
327327
excelExportOptions: {
328328
exportWithFormatter: false
329329
},
330-
registerExternalResources: [new ExcelExportService()],
330+
externalResources: [new ExcelExportService()],
331331
enableFiltering: true,
332332
enableRowSelection: true,
333333
enableCheckboxSelector: true,

src/app/examples/grid-tree-data-hierarchical.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ export class GridTreeDataHierarchicalComponent implements OnInit {
128128
exportWithFormatter: true,
129129
sanitizeDataExport: true
130130
},
131-
registerExternalResources: [new ExcelExportService()],
131+
externalResources: [new ExcelExportService()],
132132
enableFiltering: true,
133133
enableTreeData: true, // you must enable this flag for the filtering & sorting to work as expected
134134
multiColumnSort: false, // multi-column sorting is not supported with Tree Data, so you need to disable it

src/app/examples/grid-tree-data-parent-child.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ export class GridTreeDataParentChildComponent implements OnInit {
108108
enableAutoResize: true,
109109
enableExcelExport: true,
110110
excelExportOptions: { exportWithFormatter: true, sanitizeDataExport: true },
111-
registerExternalResources: [new ExcelExportService()],
111+
externalResources: [new ExcelExportService()],
112112
enableFiltering: true,
113113
showCustomFooter: true, // display some metrics in the bottom custom footer
114114
enableTreeData: true, // you must enable this flag for the filtering & sorting to work as expected

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -973,7 +973,8 @@ describe('Angular-Slickgrid Custom Component instantiated via Constructor', () =
973973
const sortServiceSpy = jest.spyOn(sortServiceStub, 'addRxJsResource');
974974
const paginationServiceSpy = jest.spyOn(paginationServiceStub, 'addRxJsResource');
975975

976-
component.gridOptions = { registerExternalResources: [rxjsMock] } as unknown as GridOption;
976+
component.gridOptions = { externalResources: [rxjsMock] } as unknown as GridOption;
977+
component.registerExternalResources([rxjsMock], true);
977978
component.initialization(slickEventHandler);
978979

979980
expect(backendUtilitySpy).toHaveBeenCalled();
@@ -1253,7 +1254,8 @@ describe('Angular-Slickgrid Custom Component instantiated via Constructor', () =
12531254
jest.spyOn((component.gridOptions as any).backendServiceApi.service, 'buildQuery').mockReturnValue(query);
12541255
const backendExecuteSpy = jest.spyOn(backendUtilityServiceStub, 'executeBackendProcessesCallback');
12551256

1256-
component.gridOptions.registerExternalResources = [rxjsMock];
1257+
component.gridOptions.externalResources = [rxjsMock];
1258+
component.registerExternalResources([rxjsMock], true);
12571259
component.gridOptions.backendServiceApi!.service.options = { executeProcessCommandOnInit: true };
12581260
component.initialization(slickEventHandler);
12591261

@@ -1328,7 +1330,9 @@ describe('Angular-Slickgrid Custom Component instantiated via Constructor', () =
13281330
jest.spyOn(component.gridOptions.backendServiceApi!.service, 'buildQuery').mockReturnValue(query);
13291331
const backendErrorSpy = jest.spyOn(backendUtilityServiceStub, 'onBackendError');
13301332

1331-
component.gridOptions.registerExternalResources = [rxjsMock];
1333+
component.gridOptions.externalResources = [rxjsMock];
1334+
component.resetExternalResources();
1335+
component.registerExternalResources([rxjsMock], true);
13321336
component.gridOptions.backendServiceApi!.service.options = { executeProcessCommandOnInit: true };
13331337
component.initialization(slickEventHandler);
13341338

0 commit comments

Comments
 (0)