Skip to content

Commit

Permalink
feat(core): refactor code using the container service everywhere (#197)
Browse files Browse the repository at this point in the history
- also removed the `internalPubSubService` since it's no longer necessary because we can now get it from the container instead
  • Loading branch information
ghiscoding committed Dec 14, 2020
1 parent 17fa349 commit 96ce9bd
Show file tree
Hide file tree
Showing 15 changed files with 186 additions and 185 deletions.
5 changes: 0 additions & 5 deletions packages/common/src/services/__tests__/shared.service.spec.ts
Expand Up @@ -268,11 +268,6 @@ describe('Shared Service', () => {
expect(service.hideHeaderRowAfterPageLoad).toEqual(true);
});

it('should call "internalPubSubService" GETTER and SETTER expect same value to be returned', () => {
service.internalPubSubService = pubSubServiceStub;
expect(service.internalPubSubService).toEqual(pubSubServiceStub);
});

it('should call "externalRegisteredResources" GETTER and return all columns', () => {
// @ts-ignore:2511
const mockRegisteredResources = [new ExcelExportService()];
Expand Down
5 changes: 3 additions & 2 deletions packages/common/src/services/excelExport.service.ts
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import { ExcelExportOption, SlickGrid } from '../interfaces/index';
import { SharedService } from '../services/shared.service';
import { ContainerService } from '../services/container.service';

export abstract class ExcelExportService {
/** ExcelExportService class name which is use to find service instance in the external registered services */
Expand All @@ -9,8 +9,9 @@ export abstract class ExcelExportService {
/**
* Initialize the Export Service
* @param _grid
* @param _containerService
*/
init(_grid: SlickGrid, _sharedService: SharedService): void {
init(_grid: SlickGrid, _containerService: ContainerService): void {
throw new Error('ExcelExportService the "init" method must be implemented');
}

Expand Down
11 changes: 0 additions & 11 deletions packages/common/src/services/shared.service.ts
@@ -1,5 +1,4 @@
import { Column, CurrentPagination, SlickDataView, GridOption, SlickGrid, SlickGroupItemMetadataProvider } from '../interfaces/index';
import { PubSubService } from '..';

export class SharedService {
private _allColumns: Column[];
Expand All @@ -11,7 +10,6 @@ export class SharedService {
private _visibleColumns: Column[];
private _hideHeaderRowAfterPageLoad = false;
private _hierarchicalDataset: any[] | undefined;
private _internalPubSubService: PubSubService;
private _externalRegisteredResources: any[];
private _frozenVisibleColumnId: string | number;

Expand Down Expand Up @@ -97,15 +95,6 @@ export class SharedService {
this._hideHeaderRowAfterPageLoad = hideHeaderRowAfterPageLoad;
}

/** Getter to know if user want to hide header row after 1st page load */
get internalPubSubService(): PubSubService {
return this._internalPubSubService;
}
/** Setter for knowing if user want to hide header row after 1st page load */
set internalPubSubService(internalPubSubService: PubSubService) {
this._internalPubSubService = internalPubSubService;
}

/** Getter to know if user want to hide header row after 1st page load */
get externalRegisteredResources(): any[] {
return this._externalRegisteredResources;
Expand Down
5 changes: 3 additions & 2 deletions packages/common/src/services/textExport.service.ts
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import { TextExportOption, SlickGrid } from '../interfaces/index';
import { SharedService } from './shared.service';
import { ContainerService } from '../services/container.service';

export abstract class TextExportService {
/** ExcelExportService class name which is use to find service instance in the external registered services */
Expand All @@ -9,8 +9,9 @@ export abstract class TextExportService {
/**
* Initialize the Export Service
* @param _grid
* @param _containerService
*/
init(_grid: SlickGrid, _sharedService: SharedService): void {
init(_grid: SlickGrid, _containerService: ContainerService): void {
throw new Error('ExportService the "init" method must be implemented');
}

Expand Down

Large diffs are not rendered by default.

Expand Up @@ -25,7 +25,6 @@ import {
SlickNamespace,
SlickDataView,
TranslaterService,
SharedService,
} from '@slickgrid-universal/common';

// using external non-typed js libraries
Expand Down Expand Up @@ -82,12 +81,16 @@ export class SlickCompositeEditorComponent {
this._bindEventService = new BindingEventService();
}

init(grid: SlickGrid, _sharedService: SharedService, containerService: ContainerService) {
init(grid: SlickGrid, containerService: ContainerService) {
this.grid = grid;
this.gridService = containerService.get<GridService>('GridService');
this.gridStateService = containerService.get<GridStateService>('GridStateService');
this.translaterService = containerService.get<TranslaterService>('TranslaterService');

if (!this.gridService || !this.gridStateService) {
throw new Error('[Slickgrid-Universal] it seems that the GridService and/or GridStateService are not being loaded properly, make sure the Container Service is properly implemented.');
}

if (this.gridOptions.enableTranslate && (!this.translaterService || !this.translaterService.translate)) {
throw new Error('[Slickgrid-Universal] requires a Translate Service to be installed and configured when the grid option "enableTranslate" is enabled.');
}
Expand Down

0 comments on commit 96ce9bd

Please sign in to comment.