From 5213c93a9fd9f2549cf13f2c3b26525bc0ba7bc0 Mon Sep 17 00:00:00 2001 From: rfrt Date: Mon, 9 Sep 2024 15:25:44 +0200 Subject: [PATCH 1/3] fix: remove all injector from constructor --- projects/core/src/services/dialog.service.ts | 11 +++++------ .../core/src/services/lazy-loader.service.ts | 6 ++---- projects/core/src/services/media.service.ts | 17 +++++++++-------- .../date-adapter/multi-format-date-adapter.ts | 13 ++++++------- .../src/message-box-dialog.service.ts | 12 +++++------- .../status-detail-dialog.service.ts | 11 ++++------- .../status-detail/status-detail.component.ts | 15 +++++++-------- projects/tooltip/src/tooltip.service.ts | 13 ++++++------- .../user-tooltip/src/user-tooltip.service.ts | 11 ++++------- 9 files changed, 48 insertions(+), 61 deletions(-) diff --git a/projects/core/src/services/dialog.service.ts b/projects/core/src/services/dialog.service.ts index 2cf6ac03..037b02a3 100644 --- a/projects/core/src/services/dialog.service.ts +++ b/projects/core/src/services/dialog.service.ts @@ -1,4 +1,4 @@ -import { Type } from '@angular/core'; +import { inject, Type } from '@angular/core'; import { MatDialog, MatDialogConfig, MatDialogRef } from '@angular/material/dialog'; import { Observable, ReplaySubject, switchMap, take, throttleTime } from 'rxjs'; @@ -9,11 +9,10 @@ export abstract class NgxDialogService { protected dialogResponse$: Observable; protected dialogRef!: MatDialogRef; - public constructor( - private lazyLoaderService: NgxLazyLoaderService, - private dialog: MatDialog, - matDialogConfig?: MatDialogConfig - ) { + protected lazyLoaderService = inject(NgxLazyLoaderService); + protected dialog = inject(MatDialog); + + public constructor(matDialogConfig?: MatDialogConfig) { this.dialogResponse$ = this.openDialogSub$.pipe( throttleTime(11), take(1), diff --git a/projects/core/src/services/lazy-loader.service.ts b/projects/core/src/services/lazy-loader.service.ts index 16c2f853..ef2f69f1 100644 --- a/projects/core/src/services/lazy-loader.service.ts +++ b/projects/core/src/services/lazy-loader.service.ts @@ -1,5 +1,5 @@ import { ComponentType } from '@angular/cdk/portal'; -import { Injectable, Injector, ɵcreateInjector as createInjector, Type } from '@angular/core'; +import { ɵcreateInjector as createInjector, inject, Injectable, Injector, Type } from '@angular/core'; import { from, map, Observable } from 'rxjs'; export interface LoadModuleInfos { @@ -17,9 +17,7 @@ export abstract class NgxAbstractLazyModule { providedIn: 'root' }) export class NgxLazyLoaderService { - public constructor( - private injector: Injector - ) {} + private injector = inject(Injector); public loadModule$>(path: Promise>, parentInjector?: Injector): Observable> { return from(path).pipe( diff --git a/projects/core/src/services/media.service.ts b/projects/core/src/services/media.service.ts index 009f700b..e948f556 100644 --- a/projects/core/src/services/media.service.ts +++ b/projects/core/src/services/media.service.ts @@ -1,4 +1,4 @@ -import { Inject, Injectable, InjectionToken, NgZone, OnDestroy, Optional } from '@angular/core'; +import { inject, Injectable, InjectionToken, NgZone, OnDestroy } from '@angular/core'; import { BehaviorSubject, distinctUntilChanged, map, Observable, shareReplay } from 'rxjs'; export interface NgxMediaQueryDefinition { @@ -97,15 +97,16 @@ export class NgxMediaService implements OnDestroy { public mediaChanged$ = new BehaviorSubject('lg'); public mql = {} as Record; - public constructor( - private zone: NgZone, - @Optional() @Inject(mediaQueryDefinitions) mediaDefinitions?: NgxMediaQueryDefinition[] - ) { - if (!mediaDefinitions) { - mediaDefinitions = simplifiedMediaQueryDefinitions; + private zone = inject(NgZone); + private mediaDefinitions? = inject>(mediaQueryDefinitions, { optional: true }); + + + public constructor() { + if (!this.mediaDefinitions) { + this.mediaDefinitions = simplifiedMediaQueryDefinitions; } - mediaDefinitions.forEach(mediaDefinition => { + this.mediaDefinitions.forEach(mediaDefinition => { const { alias, mediaQuery } = mediaDefinition; this.mql[alias] = window.matchMedia(mediaQuery); // eslint-disable-next-line @typescript-eslint/no-unsafe-argument diff --git a/projects/date-picker/src/date-adapter/multi-format-date-adapter.ts b/projects/date-picker/src/date-adapter/multi-format-date-adapter.ts index c6ed67b7..38cdbf59 100644 --- a/projects/date-picker/src/date-adapter/multi-format-date-adapter.ts +++ b/projects/date-picker/src/date-adapter/multi-format-date-adapter.ts @@ -1,9 +1,9 @@ -import { Inject, inject, Injectable, InjectionToken, Optional, Type } from '@angular/core'; +import { inject, Injectable, InjectionToken, Type } from '@angular/core'; import { DateAdapter, MAT_DATE_LOCALE } from '@angular/material/core'; import { format, isValid, Locale, setHours, setMinutes, setSeconds } from 'date-fns'; -import { validateAndParseDateStr } from './date.util'; import { DateTimeAdapter } from './date-time-adapter'; +import { validateAndParseDateStr } from './date.util'; // eslint-disable-next-line @typescript-eslint/naming-convention export const ACCEPTED_NON_DATE_VALUES = new InjectionToken('ACCEPTED_NON_DATE_VALUES'); @@ -37,13 +37,12 @@ export class NgxMultiFormatDateAdapter extends DateAdapter>>(MULTI_FORMAT_DATE_DELEGATE); // private matDateLocale = inject>(MAT_DATE_LOCALE, { optional: true }); //todo private acceptedValues = inject(ACCEPTED_NON_DATE_VALUES, { optional: true }); + private matDateLocale = inject>(MAT_DATE_LOCALE); - public constructor( - @Optional() @Inject(MAT_DATE_LOCALE) matDateLocale: Record - ) { + public constructor() { super(); - this.locale = matDateLocale; - this.delegate = new this.delegateType(matDateLocale); + this.locale = this.matDateLocale; + this.delegate = new this.delegateType(this.matDateLocale); } public getYear(date: TypeForAdapter): number { diff --git a/projects/message-box-dialog/src/message-box-dialog.service.ts b/projects/message-box-dialog/src/message-box-dialog.service.ts index 3dee4ca2..6d4d4de9 100644 --- a/projects/message-box-dialog/src/message-box-dialog.service.ts +++ b/projects/message-box-dialog/src/message-box-dialog.service.ts @@ -1,6 +1,6 @@ import { Injectable, Type } from '@angular/core'; -import { MatDialog, MatDialogConfig } from '@angular/material/dialog'; -import { NgxAbstractLazyModule, NgxDialogService, NgxLazyLoaderService } from '@hug/ngx-core'; +import { MatDialogConfig } from '@angular/material/dialog'; +import { NgxAbstractLazyModule, NgxDialogService } from '@hug/ngx-core'; import { Observable, take } from 'rxjs'; import { NgxMessageBoxDialogButtons, NgxMessageBoxDialogData, NgxMessageBoxDialogResponse } from './message-box-dialog.model'; @@ -9,11 +9,9 @@ import { NgxMessageBoxDialogButtons, NgxMessageBoxDialogData, NgxMessageBoxDialo providedIn: 'root' }) export class NgxMessageBoxDialogService extends NgxDialogService { - public constructor( - lazyLoaderService: NgxLazyLoaderService, - dialog: MatDialog - ) { - super(lazyLoaderService, dialog, { + + public constructor() { + super({ panelClass: 'no-padding-dialog' } as MatDialogConfig); } diff --git a/projects/status/src/status-detail/status-detail-dialog.service.ts b/projects/status/src/status-detail/status-detail-dialog.service.ts index 78372c10..350de36c 100644 --- a/projects/status/src/status-detail/status-detail-dialog.service.ts +++ b/projects/status/src/status-detail/status-detail-dialog.service.ts @@ -1,6 +1,6 @@ import { Injectable, Type } from '@angular/core'; -import { MatDialog, MatDialogConfig } from '@angular/material/dialog'; -import { NgxAbstractLazyModule, NgxDialogService, NgxLazyLoaderService } from '@hug/ngx-core'; +import { MatDialogConfig } from '@angular/material/dialog'; +import { NgxAbstractLazyModule, NgxDialogService } from '@hug/ngx-core'; import { NgxStatus } from '../status.model'; @@ -8,11 +8,8 @@ import { NgxStatus } from '../status.model'; providedIn: 'root' }) export class NgxStatusDetailDialogService extends NgxDialogService { - public constructor( - lazyLoaderService: NgxLazyLoaderService, - dialog: MatDialog - ) { - super(lazyLoaderService, dialog, { + public constructor() { + super({ disableClose: false, hasBackdrop: true, width: '700px', diff --git a/projects/status/src/status-detail/status-detail.component.ts b/projects/status/src/status-detail/status-detail.component.ts index dba42515..2dccf222 100644 --- a/projects/status/src/status-detail/status-detail.component.ts +++ b/projects/status/src/status-detail/status-detail.component.ts @@ -1,5 +1,5 @@ -import { ChangeDetectionStrategy, Component, Inject, ViewEncapsulation } from '@angular/core'; -import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; +import { ChangeDetectionStrategy, Component, inject, ViewEncapsulation } from '@angular/core'; +import { MAT_DIALOG_DATA } from '@angular/material/dialog'; import { NgxMessageBoxType } from '@hug/ngx-message-box'; import { NgxStatus } from '../status.model'; @@ -15,13 +15,12 @@ export class NgxStatusDetailComponent { protected fullTextError: string; protected messageBoxType: NgxMessageBoxType; - public constructor( - protected dialogRef: MatDialogRef, - @Inject(MAT_DIALOG_DATA) protected status: NgxStatus - ) { - this.fullTextError = `Error Date: ${(status.date ?? new Date()).toUTCString()}\n${status.technicalText || ''}`; + protected status = inject(MAT_DIALOG_DATA); - switch (status.type) { + public constructor() { + this.fullTextError = `Error Date: ${(this.status.date ?? new Date()).toUTCString()}\n${this.status.technicalText || ''}`; + + switch (this.status.type) { case 'primary': this.messageBoxType = 'primary'; break; diff --git a/projects/tooltip/src/tooltip.service.ts b/projects/tooltip/src/tooltip.service.ts index 6838b193..6bca0ccd 100644 --- a/projects/tooltip/src/tooltip.service.ts +++ b/projects/tooltip/src/tooltip.service.ts @@ -1,12 +1,12 @@ import { ConnectedPosition } from '@angular/cdk/overlay'; -import { Type } from '@angular/core'; +import { inject, Type } from '@angular/core'; import { MatDialog, MatDialogConfig, MatDialogRef } from '@angular/material/dialog'; import { NgxAbstractLazyModule, NgxLazyLoaderService, subscribeWith } from '@hug/ngx-core'; import { merge } from 'lodash-es'; import { debounceTime, delay, EMPTY, filter, fromEvent, map, mergeWith, Observable, shareReplay, Subject, switchMap, tap, withLatestFrom } from 'rxjs'; -import { NgxTooltipConfig } from './tooltip.model'; import { NgxTooltipComponentInterface } from './tooltip-component.interface'; +import { NgxTooltipConfig } from './tooltip.model'; export abstract class NgxTooltipService { protected close$ = new Subject(); @@ -76,11 +76,10 @@ export abstract class NgxTooltipService { } ]; - public constructor( - private lazyLoaderService: NgxLazyLoaderService, - private dialog: MatDialog, - private tooltipConfig?: MatDialogConfig - ) { + protected lazyLoaderService = inject(NgxLazyLoaderService); + protected dialog = inject(MatDialog); + + public constructor(private tooltipConfig?: MatDialogConfig) { if (!this.tooltipConfig) { this.tooltipConfig = new MatDialogConfig(); } diff --git a/projects/user-tooltip/src/user-tooltip.service.ts b/projects/user-tooltip/src/user-tooltip.service.ts index 215c2306..90988802 100644 --- a/projects/user-tooltip/src/user-tooltip.service.ts +++ b/projects/user-tooltip/src/user-tooltip.service.ts @@ -1,6 +1,6 @@ import { Injectable, Type } from '@angular/core'; -import { MatDialog, MatDialogConfig } from '@angular/material/dialog'; -import { NgxAbstractLazyModule, NgxLazyLoaderService } from '@hug/ngx-core'; +import { MatDialogConfig } from '@angular/material/dialog'; +import { NgxAbstractLazyModule } from '@hug/ngx-core'; import { NgxTooltipComponentInterface, NgxTooltipService } from '@hug/ngx-tooltip'; import { NgxUserCard } from '@hug/ngx-user-card'; @@ -8,11 +8,8 @@ import { NgxUserCard } from '@hug/ngx-user-card'; providedIn: 'root' }) export class NgxUserTooltipService extends NgxTooltipService { - public constructor( - lazyLoaderService: NgxLazyLoaderService, - dialog: MatDialog - ) { - super(lazyLoaderService, dialog, { + public constructor() { + super({ width: 'auto', minWidth: '16px', panelClass: 'no-padding-dialog' From d370d6657934ae0393849d00aa9b16da09521aff Mon Sep 17 00:00:00 2001 From: rfrt Date: Mon, 9 Sep 2024 15:26:11 +0200 Subject: [PATCH 2/3] fix: lint --- projects/core/src/services/lazy-loader.service.ts | 2 +- projects/core/src/services/media.service.ts | 2 +- .../date-picker/src/date-adapter/multi-format-date-adapter.ts | 2 +- projects/tooltip/src/tooltip.service.ts | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/projects/core/src/services/lazy-loader.service.ts b/projects/core/src/services/lazy-loader.service.ts index ef2f69f1..6756417c 100644 --- a/projects/core/src/services/lazy-loader.service.ts +++ b/projects/core/src/services/lazy-loader.service.ts @@ -1,5 +1,5 @@ import { ComponentType } from '@angular/cdk/portal'; -import { ɵcreateInjector as createInjector, inject, Injectable, Injector, Type } from '@angular/core'; +import { inject, Injectable, Injector, ɵcreateInjector as createInjector, Type } from '@angular/core'; import { from, map, Observable } from 'rxjs'; export interface LoadModuleInfos { diff --git a/projects/core/src/services/media.service.ts b/projects/core/src/services/media.service.ts index e948f556..256d8d52 100644 --- a/projects/core/src/services/media.service.ts +++ b/projects/core/src/services/media.service.ts @@ -98,7 +98,7 @@ export class NgxMediaService implements OnDestroy { public mql = {} as Record; private zone = inject(NgZone); - private mediaDefinitions? = inject>(mediaQueryDefinitions, { optional: true }); + private mediaDefinitions? = inject(mediaQueryDefinitions, { optional: true }); public constructor() { diff --git a/projects/date-picker/src/date-adapter/multi-format-date-adapter.ts b/projects/date-picker/src/date-adapter/multi-format-date-adapter.ts index 38cdbf59..4113dfd4 100644 --- a/projects/date-picker/src/date-adapter/multi-format-date-adapter.ts +++ b/projects/date-picker/src/date-adapter/multi-format-date-adapter.ts @@ -2,8 +2,8 @@ import { inject, Injectable, InjectionToken, Type } from '@angular/core'; import { DateAdapter, MAT_DATE_LOCALE } from '@angular/material/core'; import { format, isValid, Locale, setHours, setMinutes, setSeconds } from 'date-fns'; -import { DateTimeAdapter } from './date-time-adapter'; import { validateAndParseDateStr } from './date.util'; +import { DateTimeAdapter } from './date-time-adapter'; // eslint-disable-next-line @typescript-eslint/naming-convention export const ACCEPTED_NON_DATE_VALUES = new InjectionToken('ACCEPTED_NON_DATE_VALUES'); diff --git a/projects/tooltip/src/tooltip.service.ts b/projects/tooltip/src/tooltip.service.ts index 6bca0ccd..ed351409 100644 --- a/projects/tooltip/src/tooltip.service.ts +++ b/projects/tooltip/src/tooltip.service.ts @@ -5,8 +5,8 @@ import { NgxAbstractLazyModule, NgxLazyLoaderService, subscribeWith } from '@hug import { merge } from 'lodash-es'; import { debounceTime, delay, EMPTY, filter, fromEvent, map, mergeWith, Observable, shareReplay, Subject, switchMap, tap, withLatestFrom } from 'rxjs'; -import { NgxTooltipComponentInterface } from './tooltip-component.interface'; import { NgxTooltipConfig } from './tooltip.model'; +import { NgxTooltipComponentInterface } from './tooltip-component.interface'; export abstract class NgxTooltipService { protected close$ = new Subject(); From 65597227b752f856f64ec6724524f09676990702 Mon Sep 17 00:00:00 2001 From: rfrt Date: Mon, 9 Sep 2024 15:47:15 +0200 Subject: [PATCH 3/3] feat: remove module --- .../story-book/src/numeric-stepper/numeric-stepper.stories.ts | 4 ++-- projects/story-book/src/overlay/overlay.stories.ts | 4 ++-- .../src/search-container/search-container.stories.ts | 4 ++-- projects/story-book/src/splitter/splitter.stories.ts | 4 ++-- projects/story-book/src/user-card/user-card.stories.ts | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/projects/story-book/src/numeric-stepper/numeric-stepper.stories.ts b/projects/story-book/src/numeric-stepper/numeric-stepper.stories.ts index ebe061b7..d3767295 100644 --- a/projects/story-book/src/numeric-stepper/numeric-stepper.stories.ts +++ b/projects/story-book/src/numeric-stepper/numeric-stepper.stories.ts @@ -1,4 +1,4 @@ -import { FormsModule, ReactiveFormsModule } from '@angular/forms'; +import { FormsModule } from '@angular/forms'; import { MatButtonToggle, MatButtonToggleGroup } from '@angular/material/button-toggle'; import { MatFormField, MatLabel, MatPrefix, MatSuffix } from '@angular/material/form-field'; import { MatInput } from '@angular/material/input'; @@ -18,7 +18,7 @@ const meta: Meta = { }), moduleMetadata({ imports: [ - MatLabel, MatInput, MatPrefix, MatSuffix, MatFormField, ReactiveFormsModule, FormsModule + MatLabel, MatInput, MatPrefix, MatSuffix, MatFormField, FormsModule ] }) ], diff --git a/projects/story-book/src/overlay/overlay.stories.ts b/projects/story-book/src/overlay/overlay.stories.ts index d61653bf..16405be8 100644 --- a/projects/story-book/src/overlay/overlay.stories.ts +++ b/projects/story-book/src/overlay/overlay.stories.ts @@ -1,4 +1,4 @@ -import { FormsModule, ReactiveFormsModule } from '@angular/forms'; +import { FormsModule } from '@angular/forms'; import { MatButton, MatIconButton } from '@angular/material/button'; import { MatFormField, MatHint, MatLabel } from '@angular/material/form-field'; import { MatIcon } from '@angular/material/icon'; @@ -113,7 +113,7 @@ export const overlayWidth: Story = { decorators: [ moduleMetadata({ imports: [ - MatFormField, MatLabel, MatHint, FormsModule, MatInput, ReactiveFormsModule + MatFormField, MatLabel, MatHint, FormsModule, MatInput ] }) ], diff --git a/projects/story-book/src/search-container/search-container.stories.ts b/projects/story-book/src/search-container/search-container.stories.ts index 2e3bbc02..a85dac15 100644 --- a/projects/story-book/src/search-container/search-container.stories.ts +++ b/projects/story-book/src/search-container/search-container.stories.ts @@ -1,6 +1,6 @@ import { FormsModule } from '@angular/forms'; import { MatList, MatListItem } from '@angular/material/list'; -import { MatTooltipModule } from '@angular/material/tooltip'; +import { MatTooltip } from '@angular/material/tooltip'; import { type Meta, moduleMetadata, type StoryObj } from '@storybook/angular'; import { NgxSearchContainerComponent, NgxSearchInputDirective } from '../../../search-container/src/search-container.component'; @@ -13,7 +13,7 @@ const meta: Meta = { moduleMetadata({ imports: [ NgxSearchInputDirective, - MatTooltipModule, + MatTooltip, FormsModule ] }) diff --git a/projects/story-book/src/splitter/splitter.stories.ts b/projects/story-book/src/splitter/splitter.stories.ts index 4634ba16..e0609a77 100644 --- a/projects/story-book/src/splitter/splitter.stories.ts +++ b/projects/story-book/src/splitter/splitter.stories.ts @@ -1,4 +1,4 @@ -import { FormsModule, ReactiveFormsModule } from '@angular/forms'; +import { FormsModule } from '@angular/forms'; import { MatButtonToggle, MatButtonToggleGroup } from '@angular/material/button-toggle'; import { MatFormField, MatLabel } from '@angular/material/form-field'; import { MatInput } from '@angular/material/input'; @@ -252,7 +252,7 @@ export const customizableSplitAreas: Story = { decorators: [ moduleMetadata({ imports: [ - MatFormField, MatLabel, FormsModule, MatInput, ReactiveFormsModule + MatFormField, MatLabel, FormsModule, MatInput ] }) ], diff --git a/projects/story-book/src/user-card/user-card.stories.ts b/projects/story-book/src/user-card/user-card.stories.ts index 6606ede4..840b66ec 100644 --- a/projects/story-book/src/user-card/user-card.stories.ts +++ b/projects/story-book/src/user-card/user-card.stories.ts @@ -1,4 +1,4 @@ -import { MatButtonToggleModule } from '@angular/material/button-toggle'; +import { MatButtonToggle } from '@angular/material/button-toggle'; import { type Meta, moduleMetadata, type StoryObj } from '@storybook/angular'; import { NgxUserCardComponent } from '../../../user-card/src/user-card.component'; @@ -11,7 +11,7 @@ const meta: Meta = { decorators: [ moduleMetadata({ imports: [ - MatButtonToggleModule + MatButtonToggle ] }) ],