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

fix: spreading 2 grids options causes duplicate ext resources #1126

Merged
merged 1 commit into from
Dec 15, 2023
Merged
Changes from all 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
25 changes: 15 additions & 10 deletions src/aurelia-slickgrid/custom-elements/aurelia-slickgrid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,6 @@ export class AureliaSlickgridCustomElement {
throw new Error('Using `<aurelia-slickgrid>` requires `grid-options.bind` and `column-definitions.bind`, it seems that you might have forgot to provide them since at least of them is undefined.');
}

// save resource refs to register before the grid options are merged and possibly deep copied
// since a deep copy of grid options would lose original resource refs but we want to keep them as singleton
this._registeredResources = this.gridOptions?.externalResources || [];

this._eventHandler = new SlickEventHandler();
this.initialization(this._eventHandler);
this._isGridInitialized = true;
Expand Down Expand Up @@ -1341,6 +1337,8 @@ export class AureliaSlickgridCustomElement {

/** Pre-Register any Resource that don't require SlickGrid to be instantiated (for example RxJS Resource & RowDetail) */
protected preRegisterResources() {
this._registeredResources = this.gridOptions?.externalResources || [];

// bind & initialize all Components/Services that were tagged as enabled
// register all services by executing their init method and providing them with the Grid object
if (Array.isArray(this._registeredResources)) {
Expand All @@ -1351,7 +1349,7 @@ export class AureliaSlickgridCustomElement {
}
}

if (this.gridOptions.enableRowDetailView) {
if (this.gridOptions.enableRowDetailView && !this._registeredResources.some(r => r instanceof SlickRowDetailView)) {
this.slickRowDetailView = new SlickRowDetailView(this.aureliaUtilService, this._eventPubSubService, this.elm as HTMLElement);
this.slickRowDetailView.create(this.columnDefinitions, this.gridOptions);
this._registeredResources.push(this.slickRowDetailView);
Expand All @@ -1366,15 +1364,20 @@ export class AureliaSlickgridCustomElement {
}

// push all other Services that we want to be registered
this._registeredResources.push(this.gridService, this.gridStateService);
if (!this._registeredResources.some(r => r instanceof GridService)) {
this._registeredResources.push(this.gridService);
}
if (!this._registeredResources.some(r => r instanceof GridStateService)) {
this._registeredResources.push(this.gridStateService);
}

// when using Grouping/DraggableGrouping/Colspan register its Service
if (this.gridOptions.createPreHeaderPanel && !this.gridOptions.enableDraggableGrouping) {
if (this.gridOptions.createPreHeaderPanel && !this.gridOptions.enableDraggableGrouping && !this._registeredResources.some(r => r instanceof GroupingAndColspanService)) {
this._registeredResources.push(this.groupingService);
}

// when using Tree Data View, register its Service
if (this.gridOptions.enableTreeData) {
if (this.gridOptions.enableTreeData && !this._registeredResources.some(r => r instanceof TreeDataService)) {
this._registeredResources.push(this.treeDataService);
}

Expand All @@ -1384,8 +1387,10 @@ export class AureliaSlickgridCustomElement {
}

// also initialize (render) the empty warning component
this.slickEmptyWarning = new SlickEmptyWarningComponent();
this._registeredResources.push(this.slickEmptyWarning);
if (!this._registeredResources.some(r => r instanceof SlickEmptyWarningComponent)) {
this.slickEmptyWarning = new SlickEmptyWarningComponent();
this._registeredResources.push(this.slickEmptyWarning);
}

// bind & initialize all Components/Services that were tagged as enabled
// register all services by executing their init method and providing them with the Grid object
Expand Down